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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,222,228
Messages
6,164,728
Members
451,912
Latest member
HMF009

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