简体   繁体   English

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

[英]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.

相关问题 如何使用VBA宏在Powerpoint幻灯片中“重置图片”? - How to “Reset Picture” in Power point Slide using VBA macro? 如何在MS Power Point演示文稿的一张主幻灯片中添加自定义文本占位符,并为每张幻灯片使用VBA脚本对其进行访问? - How to add a custom Text placeholder in one of the master slides in MS Power Point presentation and access it using VBA Script for each slide? 在PowerPoint中使用VBA宏将超链接添加到图片 - Add hyperlink to picture using VBA Macro in PowerPoint VBA 图片阴影宏 - VBA Picture Shadow Macro VBA Excel -> 在页码下方添加图片 - VBA Excel -> Add picture below page number VBA / Powerpoint:如何列出哪些幻灯片属于任何现有幻灯片母版? - VBA/Powerpoint: How can I list which slides belong to any existing slide masters? VBA Do While循环中的宏无法复制幻灯片并在Powerpoint中更改图片时出现问题 - Trouble with VBA Do While loop in macro to copy slide and change picture in powerpoint PowerPoint 宏 - 需要为每张幻灯片添加带有注释的矩形 - PowerPoint Macro - Need to add Rectangle with Notes to each Slide 如何通过更改幻灯片在 PowerPoint VBA 中重新启动宏 - How to restart macro in PowerPoint VBA by changing slides VBA 宏报告PowerPoint幻灯片上的链接 - VBA Macro to report links on powerpoint slides
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM