jz22
jz22

Reputation: 2638

PowerPoint macro to insert a picture into a frame

I have a PowerPoint file with a content placeholder frame named "image2" on slide 22. There is an image called hello.png in a folder somewhere on my computer. Now I need a macro to put the image into this frame. It is important that the image is having the size and the position of the frame after it is imported.

I found this piece of code on the internet but it doesn't work for me.

ActivePresentation.Slides(22).Shapes("image2").Picture = LoadPicture("path to the image")

It says method or data member not found. I also found the method addPicture but it doesn't work either.

Can you help me out? Thanks in advance.

Upvotes: 2

Views: 1577

Answers (1)

Zsmaster
Zsmaster

Reputation: 1559

try the following code:

Public Sub InsertPic()
    Set myDocument = ActivePresentation.Slides(2)
    myDocument.Shapes.AddPicture FileName:="d:\pic.jpg", LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=100, Top:=100, Width:=200, Height:=200
End Sub

Upvotes: 2

Related Questions