我是 VBA 新手。我正在使用 powerpoint 编写 VBA 代码来添加 n 张幻灯片,并且每张幻灯片应包含从所选路径中选择的图片。我尝试过以下代码,该代码仅添加一张幻灯片以及一个用于向每张幻灯片添加图片的不同宏。所以我的问题是,例如,我想要 40 张幻灯片,并在所有幻灯片中选择图片。任何类型的提示将不胜感激。
添加幻灯片的代码:
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
您可以使用循环来实现您的目标。
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