VBA 宏可添加任意数量的幻灯片,每张幻灯片中都有图片

问题描述 投票:0回答:1

我是 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 
vba powerpoint
1个回答
1
投票

您可以使用循环来实现您的目标。

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
© www.soinside.com 2019 - 2024. All rights reserved.