VBA Pasting Excel to PowerPoint as images

pliskers

Active Member
Joined
Sep 26, 2002
Messages
462
Office Version
  1. 2016
Platform
  1. Windows
I am using some code to paste images of Excel sheets into PowerPoint. All works fine until the code encounters a sheet that also contains a graph. When it reaches the code to paste, I get an error message.

Here's a snippet of the code for a sample sheet:

Sheets("P20_9. Inc.Tax").Select
Range("P20_9").Activate
ActiveSheet.Outline.ShowLevels RowLevels:=1
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1

' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture

' Initialize PowerPoint Object Library
Set PPApp = GetObject(, "Powerpoint.Application")

' Reference active presentation
Set ppPres = PPApp.ActivePresentation


' Denote slide where range is to be copied and paste image
Set PPSlide = ppPres.Slides(20).Shapes.Paste

Is there an alternate code that I can use to capture BOTH the graph and the other data in the sheet and paste them as a single image to PowerPoint?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Having a chart on a worksheet shouldn't cause an error. In fact, I tested it, and the cells along with the chart were pasted into the slide successfully. As it stands, your code pastes the picture in the 20th slide. Do you in fact have a 20th slide? Also, can you please confirm with line causes the error, and the type of error you're getting?
 
Upvote 0
Something else was causing the issue. It works fine now, including copying/pasting the images of tabs that include charts. Thanks for your reply!
 
Upvote 0
That's great, I'm glad you were able to solve the issue. Thanks for the update.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top