PowerPoint VBA insert Slide and insert Picture

bobaol

Board Regular
Joined
Jun 3, 2002
Messages
190
Office Version
  1. 365
  2. 2003 or older
Platform
  1. Windows
I would like to use VBA to insert a new slide, then insert an image to the slide. I have 14 jpg images. here is an example of the name for three images: c:\temp2\jkflaj1.jpg c:\temp2\98u98s2.jpg c:\temp2\hga3.jpg I want to explicitly define my image and location. so, the code would need to go like this:

  1. insert slide (slide2), insert image c:\temp2\jkflaj1.jpg. this image would remain on slide 2, not move to another slide
  2. insert another slide (slide3), insert image c:\temp2\98u98s2.jpg this image would remain on slide 3, not move to another slide
  3. insert another slide (slide4), insert image c:\temp2\hga3.jpg this image would remain on slide 4, not move to another slide
I want to use a hard-path and a hard file-name. i know i will need to do this 14 times, but i am okay with it. any help is appreciated. thank you in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Something like this.

I used png's, change them to jpg's

VBA Code:
Sub InsertImages()
    Dim nSlide As slide
    
    Set nSlide = InsertImageOnSlide(2, "c:\temp2\jkflaj1.png")
    Set nSlide = InsertImageOnSlide(3, "c:\temp2\98u98s2.png")
    Set nSlide = InsertImageOnSlide(4, "c:\temp2\hga3.png")
End Sub


Function InsertImageOnSlide(slideIndex As Integer, imagePath As String) As slide
    Dim nSlide As slide
    
    Set nSlide = ActivePresentation.Slides.Add(slideIndex, ppLayoutBlank)
        nSlide.Shapes.AddPicture FileName:=imagePath, LinkToFile:=msoFalse, _
        SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=100, Height:=100
    Set InsertImageOnSlide = nSlide
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,215,103
Messages
6,123,108
Members
449,096
Latest member
provoking

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