首页 文章

使用VBA从Excel打开PowerPoint演示文稿,然后将该演示文稿设置为变量

提问于
浏览
1

我必须将大量Excel图表发布到特定的PowerPoint文档中,然后在Excel VBA中构建一个宏来为我完成 .

我知道如何设置我刚刚打开一个名为 MyPresentation 的变量的演示文稿 .

Dim myPresentation As PowerPoint.Presentation
Dim PowerPointApp As PowerPoint.Application

PowerPointApp.Presentations.Open Filename:="obscured filepath and name"`

显然有's some additional code, but I' m试图将我刚刚在第3行设置的Presentation设置为 MyPresentation 变量,所以我可以引用我刚打开的文档 .

2 回答

  • 0

    我最终找到了MVP Andy Pope的解决方案 .

    一些相关的代码片段供未来用户使用 . (仅供我参考,当我遇到问题时,我的PPT已经可见)

    Dim DestinationPPT As String
    Dim PowerPointApp As PowerPoint.Application
    Dim myPresentation As PowerPoint.Presentation
    
    'Easier to define manually set links up front so it's easier to change/modify
    DestinationPPT = "C:\yourfilepath\yourfilename.pptx"`
    

    查看Spreadsheet Guru从Excel VBA打开PPT的指南

    然后:

    Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
    
  • 5

    首先,你必须为使用ppt文件铺平道路,我做了什么:

    Dim DestinationPPT As String
    Dim PowerPointApp As PowerPoint.Application
    Dim myPresentation As PowerPoint.Presentation
    
    Set PowerPointApp = CreateObject("PowerPoint.Application")
    
    DestinationPPT = "path"
    PowerPointApp.Presentations.Open (DestinationPPT)
    

相关问题