adding a picture using vba

C

Candace

Can someone please help me with a line or two of code that would allow me to
insert a picture (from file) into my slideshow using vba code?

I know how to use the buttons of the Powerpoint interface to add pictures to
a presentation. But I need to add approximately 50 pictures throughout my
presentation and would rather do so with code than with a bunch of mouse
clicks and file selections.

Thanks.
 
V

vindys

Hi Candace,

Dim path As String
path = "C:\1.jpg"

Dim s As Shape
Set s = ActiveWindow.Selection.SlideRange(1).Shapes.AddPicture(path,
msoFalse, msoCTrue, 10, 10, 600, 450)

This is the code for adding a picture at coordinate 10,10 with width 600 and
height 450. If you need open file to pop up to select te picture, you can
check this link: http://www.meadinkent.co.uk/aopendlg.htm

Thanks,
Vindys
 
C

Candace

Okay, I tied the "GetStarted" procedure from the following code to a shape on
my slideshow, but nothing happened. Any suggestions?

Dim path As String
path = "C:\student\20080421\Math_p283_13-21_pictures"

Sub GetStarted()
path14 = path & "\14-01.png"
Dim s As Shape
Set s = ActivePresentation.Slides("problem14").Shapes.AddPicture(path14, _
msoFalse, msoCTrue, 10, 10, 600, 450)
End Sub
 
V

vindys

Candace,
I think the function is fine other than that path =
"C:\student\20080421\Math_p283_13-21_pictures" will give "Invalid outside
Procedure if you defining the string outside procedure. So make it as a Const
if you want to define it outside procedure.
Const path As String = "C:\student\20080421\Math_p283_13-21_pictures"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top