# MS Powerpoint Macro to insert images from file



## Gerald Higgins (Mar 15, 2011)

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

```
'===== 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.


----------

