MS Powerpoint Macro to insert images from file

Gerald Higgins

Well-known Member
Joined
Mar 26, 2007
Messages
9,258
Hi all

Still finding my way in Excel VBA, and now dipping my toe into Powerpoint VBA.

I've used the Powerpoint macro recorder to build up some code which is supposed to create 8 new slides one at a time, and on each one, insert an image from file.

Here's the code I have now
Rich (BB code):
'===== INSERT 8 BLANK PAGES (AND APPLY BLANK SLIDE LAYOUT) =====
    ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutBlank).Select
        ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="C:\image002.gif", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=-5, Top:=45, Width:=733, Height:=450).Select
    ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutBlank).Select
        ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="C:\image003.gif", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=-5, Top:=45, Width:=733, Height:=450).Select
 
.....and so on, for the rest of the 8 slides

When I run this, it gives me this error
"Run-time error '-2147188160(80048240)'
Shape(unknown member):Invalid request. To select a shape, its view must be active."
And the line of code that I've put in bold is highlighted.

Anybody have any ideas what I'm doing wrong, and what I should be doing ?

As I said, this is basically code that I got via the recorder, and I have no idea how (or why) I should activate the shape's view.

Thanks in advance.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,224,524
Messages
6,179,310
Members
452,906
Latest member
phanmemchatdakenhupviral

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