简体   繁体   中英

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. Each page contains an image (a screenshot). I want to create a PowerPoint document and for each images in the MS Word document; 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

Not sure why you aer using ActivePresentation when you create a Presentation object. Anyway, here is how you can add a slide. You use the Add method of the CustomeLayouts collection, then you can add a slide

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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