I am new to VBA. I am using powerpoint to write a VBA code to add n number of slides and each slide should contain selected picture from the selected path. I have tried following code which is only adding one slide and also a different macro for adding picture to each slide. So my problem is for example i would like to have 40 slides with selected picture to all the slides. Any type of hint would be appreciated.
code to add slide:
Public Sub Add_Example()
Dim pptSlide As Slide
Dim pptLayout As CustomLayout
Set pptLayout = ActivePresentation.Slides(1).CustomLayout
Set pptSlide = ActivePresentation.Slides.AddSlide(2, pptLayout)
End Sub
You can use loops for your goal.
Public Sub Add_Example()
Dim pptSlide as Slide Dim pptLayout As CustomLayout Dim SlideCount as Integer Dim FilePath as String
SlideCount = 40 ' add your file path FilePath = " Your path of file "
Set pptLayout = ActivePresentation.Slides(1).CustomLayout
For i=1 to SlideCount
Set pptSlide = ActivePresentation.Slides.AddSlide(i+1, pptLayout)
pptSlide.Shapes.AddPicture FileName:=FilePath, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=100, Top:=100
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.