[英]VBA macro to add any number of slides with a picture in each slide
I am new to VBA.我是 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.
我正在使用 powerpoint 编写 VBA 代码来添加 n 张幻灯片,并且每张幻灯片都应包含从所选路径中选择的图片。 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.
所以我的问题是例如我想有 40 张带有选定图片的幻灯片到所有幻灯片。 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()公共子 Add_Example()
Dim pptSlide as Slide Dim pptLayout As CustomLayout Dim SlideCount as Integer Dim FilePath as String Dim pptSlide 作为 Slide Dim pptLayout 作为 CustomLayout Dim SlideCount 作为 Integer Dim FilePath 作为 String
SlideCount = 40 ' add your file path FilePath = " Your path of file " SlideCount = 40 ' 添加你的文件路径 FilePath = " 你的文件路径 "
Set pptLayout = ActivePresentation.Slides(1).CustomLayout设置 pptLayout = ActivePresentation.Slides(1).CustomLayout
For i=1 to SlideCount对于 i=1 到 SlideCount
Set pptSlide = ActivePresentation.Slides.AddSlide(i+1, pptLayout)设置 pptSlide = ActivePresentation.Slides.AddSlide(i+1, pptLayout)
pptSlide.Shapes.AddPicture FileName:=FilePath, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=100, Top:=100 pptSlide.Shapes.AddPicture FileName:=FilePath, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=100, Top:=100
Next下一个
End Sub结束子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.