【问题标题】:PowerPoint Macro - Paste Slides and Keep Source FormattingPowerPoint 宏 - 粘贴幻灯片并保留源格式
【发布时间】:2021-12-17 23:24:45
【问题描述】:

我有一组核心幻灯片,可以插入到我保存在桌面上的所有演示文稿中。我编写了一个宏来复制这些幻灯片并将它们粘贴到当前打开的演示文稿中,但我丢失了源格式。我阅读了一些其他类似的帖子,但我似乎无法让 ExecuteMso 命令工作:

Sub insertSlides()
    
    Dim objPresentation As Presentation
    Dim currPresentation As Presentation
    Set currPresentation = Application.ActivePresentation
    
    Set objPresentation = Presentations.Open("C:\Users\Me\Desktop\coreSlides.pptx", , False)
    objPresentation.Slides.Item(1).Copy
    currPresentation.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
    objPresentation.Close
    
 End Sub

另外,您可以使用此命令在幻灯片 2 之后始终粘贴幻灯片吗?

【问题讨论】:

  • 基于此answer,您似乎缺少导航到目标演示文稿的幻灯片部分,因此请在执行命令之前尝试插入currPresentation.Windows(1).View.GotoSlide(2)。 @user3390169
  • “我有一组核心幻灯片,可以插入到我的所有演示文稿中”简化您的生活。创建一个已包含这些幻灯片及其布局的新模板。那么您就不需要复制或粘贴或 VBA。
  • @raymondwu 该答案解决了在某张幻灯片上插入的问题,谢谢!但是格式呢?它似乎仍然没有遵循原版
  • @user3390169 恐怕我无法帮助您,因为我首先不熟悉 PP VBA!但 John 的建议是正确的 - 如果您有一组幻灯片需要用于所有演示文稿,那么您应该使用这些幻灯片和正确的布局制作一个模板。

标签: vba powerpoint


【解决方案1】:

我在您的代码中添加了一行,这对我来说非常有用,并在保留原始格式的同时粘贴了幻灯片。 currPresentation.Windows.Item(1).Activate

但是幻灯片的大小没有保存,如果需要可以根据原演示文稿中的大小明确设置。

Sub insertSlides()
    
    Dim objPresentation As Presentation
    Dim currPresentation As Presentation
    Set currPresentation = Application.ActivePresentation
    
    Set objPresentation = Presentations.Open("F:\1.pptx", , False)
    objPresentation.Slides.Item(1).Copy
    currPresentation.Windows.Item(1).Activate ' NEW LINE !
    currPresentation.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
    objPresentation.Close
    
 End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-15
    • 2020-05-18
    • 1970-01-01
    • 2018-12-15
    • 2020-07-09
    • 1970-01-01
    相关资源
    最近更新 更多