简体   繁体   English

从 MS Word,如何使用 VBA 在 Powerpoint 中添加幻灯片

[英]From MS Word, how can I add a slide in Powerpoint using VBA

I am trying to add a slide in a Presentation but I am having an error.我正在尝试在演示文稿中添加幻灯片,但出现错误。

在此处输入图片说明

Context : I have a word file that contains more than 200 pages.上下文:我有一个包含 200 多页的 word 文件。 Each page contains an image (a screenshot).每个页面都包含一个图像(屏幕截图)。 I want to create a PowerPoint document and for each images in the MS Word document;我想为 MS Word 文档中的每个图像创建一个 PowerPoint 文档; I want to paste the picture in a blank layout slides.我想将图片粘贴到空白布局幻灯片中。

Sub transfert_image_from_WORD_to_PowerPoint()
'I added a Reference Object to this Module (PowerPoint)

'Variable creation
Dim pptPres As PowerPoint.Presentation
Dim pptApp As PowerPoint.Application

Set pptApp = CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres = pptApp.Presentations.Add

'add Slides
Dim pptSlide As Slide
Dim pptLayout As CustomLayout

Set pptLayout = ActivePresentation.Slides(0).CustomLayout
'Set pptSlide = ActivePresentation.Slides.AddSlide(0, pptLayout)

'Word object creation to contains images.
Dim pic As InlineShape
Dim pslides As Slides

'loop through eanch Picutures in MS Word
For Each pic In ActiveDocument.InlineShapes
    pic.Select
    Selection.Copy
    'Selection.PasteAndFormat wdPasteDefault
Next

End Sub

I have an error in the line Set pptLayout我在Set pptLayout行中有错误

Not sure why you aer using ActivePresentation when you create a Presentation object.不确定为什么在创建 Presentation 对象时使用 ActivePresentation。 Anyway, here is how you can add a slide.无论如何,这是添加幻灯片的方法。 You use the Add method of the CustomeLayouts collection, then you can add a slide你使用CustomeLayouts集合的Add方法,然后就可以添加幻灯片了

Set pptLayout = pptPres.SlideMaster.CustomLayouts.Add(1)
Set pptSlide = pptPres.Slides.AddSlide(1, pptLayout)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM