Macro to load photo from a directory into powerpiont slide

  • Thread starter Thread starter Blaine76
  • Start date Start date
B

Blaine76

Hi All

I hope someone has some help for me. I am wanting to create a macro
that inserts a photo into an active slide. All photos will be placed in
one directory eg.(c:\temp\) It would be great if I could be prompted
with a message box witch asked for the filename.

Anyone have any ideas. I did find one piece of code but I just could
not get it to pull the photo into the current slide. It kept creating a
new slide and inserting the photo there.

Any help would be greatly apprieciated.

Thanks in advance
 
This is the code I have so far

Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape

' Edit these to suit:
strPath = "c:\temp\"
strFileSpec = "browning.bmp"

strTemp = Dir(strPath & strFileSpec)

'Do While strTemp <> ""
Set oSld =
ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 0,
ppLayoutChart)
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=10, _
Top:=20, _
Width:=150, _
Height:=100)
 
' Inserts specified slide into the current slide assuming that the current
view suitable for image import.

Dim strPath As String
Dim strFileSpec As String
Dim oPic As Shape

' Edit these to suit:
strPath = "I:\Under development\My Pictures\"
strFileSpec = "sample.jpg"


With ActiveWindow.View.Slide.Shapes
Set oPic = .AddPicture(FileName:=strPath & strFileSpec, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=10, _
Top:=20, _
Width:=150, _
Height:=100)
End With
 
Thank you Shyam

That works great. !!! One more question. Instead of hardcoding the
filename in is it possible to have a msgbox ask for the file name? eg.
mvc-001

Thanks again
 
strFileSpec = InputBox("What is the name of the file?")

The only difficulty is that you might need to add error checking in case
no file of that name exists.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
Thanks David that works great.

If I used

If strFileSpec = "" Then End

Work for error checking, Sorry Im new to this
 
That will certainly help, but it will only check to see that the user didn't
type anything. What if they type a file name that doesn't exist. You can
probably handle it with a generic OnError bit of code after trying to open
the file.
--David

David Marcovitz
Microsoft PowerPoint MVP
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
I am sorry but this is the only thing that this site is letting me get into
right now. I cannot create a new message, I cannot create a new comment and
it is frustrating me beyond belief! I click on New and then Question or
General Comment and nothing happens. The screen flashes really quickly like
it refreshed but nothing else.

Can you help, per chance?
 
Amber are you using Microsoft newsgroups? If so I have the same
problem.
Search for powerpoint in google groups!


Microsoft.public.powerpoint in google groups is the same place
 
David M. said:
That will certainly help, but it will only check to see that the user didn't
type anything. What if they type a file name that doesn't exist. You can
probably handle it with a generic OnError bit of code after trying to open
the file.

If Len(Dir$(strFileSpec)) = 0 Then
' The file's not there
MsgBox "No file by that name."
Exit Sub
End If
 

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

Back
Top