首页 > 解决方案 > 将幻灯片从模板 PPT 复制/粘贴到打开的 PPT 中的当前位置

问题描述

我正在尝试组合一个宏,以便在运行它时将幻灯片从模板演示文稿复制/粘贴到活动演示文稿中的当前幻灯片之后。我已经完成了 90% 的工作,但似乎无法弄清楚如何使粘贴部分按需要发挥作用。我所能找到的只是如何将它粘贴到指定位置(例如,幻灯片 4),或在演示文稿的末尾。

这是迄今为止我提到的 MS 资源:https ://docs.microsoft.com/en-us/office/vba/api/powerpoint.slides.paste

这是我的代码的当前版本:

  Sub PastefromTemplate()
  Dim tgt, i%

  'open the target presentation
  'use path with the file if it is in a different location
  Set objPresentation = Presentations.Open("source path")

  'copy slide 1 from source presentation
  'change the item number in order to target a different slide
  objPresentation.Slides.Item(1).Copy
 
  'paste the slide in target, currently set to slide 3
  tgt = Array(3)
  Presentations.Item(1).Slides.Paste tgt i

  objPresentation.Close
  End Sub

谢谢你的帮助!

标签: vbapowerpointcopy-paste

解决方案


这是解决方案,终于能够弄清楚:

Sub Slide9()
Dim src As Presentation
Dim trg As Slide
Dim shp As Shape
Dim target As Presentation

'Copies slide (change # in Item(#)) from the source presentation
Set objPresentation = Presentations.Open("source file path")
objPresentation.Slides.Item(9).Copy
 
'Closes the source presentation
objPresentation.Close

'Go back to active presentation and paste, then go to pasted slide
With ActiveWindow.View
.Paste
.GotoSlide (ActiveWindow.View.Slide.SlideIndex)
End With
        
End Sub

推荐阅读