简体   繁体   English

Excel VBA 在 PowerPoint 中复制幻灯片

[英]Excel VBA Duplicating a Slide in PowerPoint

I am working on exporting Contents from Excel to PowerPoint.我正在将内容从 Excel 导出到 PowerPoint。 I have a blank formatted slide in my PowerPoint presentation which I Need to duplicate everytime and write on it.我的 PowerPoint 演示文稿中有一张空白格式的幻灯片,我每次都需要复制它并在上面书写。 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.在自动化 PPT 时几乎没有充分的理由选择任何内容。 Assuming a shape named Table 1 on Slide 1, this should do what you want:假设幻灯片 1 上有一个名为 Table 1 的形状,这应该可以满足您的需求:

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.Range(1).Cut

ActivePresentation.Slides.Paste -1 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如果您需要知道范围内有多少张幻灯片,它是 ActivePresentation.Slides.Range.count

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

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