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

时间:2021-11-29 13:03:05

I have to post a lot of Excel charts to a specific PowerPoint document and I'm building out a macro in Excel VBA to do it for me.

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

I'm able to correctly open the PowerPoint presentation that I want to update, however I don't know how to set the presentation I just opened to a variable called MyPresentation.

我能够正确地打开我想要更新的PowerPoint演示文稿,但是我不知道如何设置我刚刚打开的演示文稿到名为MyPresentation的变量。

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

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

Obviously there's some additional code, but I'm trying to set the Presentation I just opened in line 3 set to the MyPresentation variable so I can reference the document I just opened.

显然还有一些额外的代码,但我正在尝试将我刚刚在第3行中设置的Presentation设置为MyPresentation变量,这样我就可以引用刚刚打开的文档。

2 个解决方案

#1


3  

I ended up finding a solution by the MVP Andy Pope.

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

Some relevant code snippets for future users. (FYI My PPT was already visible when I ran into the problem)

一些相关的代码片段供未来用户使用。 (仅供我参考,当我遇到问题时,我的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"`

Lookup the Spreadsheet Guru's guide to opening PPT from Excel VBA

查看电子表格大师从Excel VBA打开PPT的指南

Then:

Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

#2


0  

First you have to pave the way for using ppt files, what I did:

首先,你必须为使用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)

#1


3  

I ended up finding a solution by the MVP Andy Pope.

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

Some relevant code snippets for future users. (FYI My PPT was already visible when I ran into the problem)

一些相关的代码片段供未来用户使用。 (仅供我参考,当我遇到问题时,我的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"`

Lookup the Spreadsheet Guru's guide to opening PPT from Excel VBA

查看电子表格大师从Excel VBA打开PPT的指南

Then:

Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

#2


0  

First you have to pave the way for using ppt files, what I did:

首先,你必须为使用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)