简体   繁体   中英

Excel VBA Duplicating a Slide in PowerPoint

I am working on exporting Contents from Excel to PowerPoint. I have a blank formatted slide in my PowerPoint presentation which I Need to duplicate everytime and write on it. The Problem is that my code adds a new slide ahead of the current slide which is posing Problems in writing the Contents to the exact slide number. I want that the new slide should be added after the current slide.

        Set pptSlide = oPPTApp.ActivePresentation.Slides(1).Duplicate.Item(1)
        oPPTFile.Slides(SlideNum).Select
        Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table 1")  

any Suggestions ?

There's almost NEVER a good reason to select anything when automating PPT. Assuming a shape named Table 1 on Slide 1, this should do what you want:

Dim oSl As Slide
Dim oSh As Shape

Set oSl = ActivePresentation.Slides(1).Duplicate()(1)
Set oSh = oSl.Shapes("Table 1")

ActivePresentation.Slides.Range(1).Cut

ActivePresentation.Slides.Paste -1

this function will move the first slide to the last. so it stands to reason you could figure out a formula to keep track of where you want the slide inserted. if you need to know how many slides are in the range it's ActivePresentation.Slides.Range.count

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