使用 VBA 从 Excel 中打开 PowerPoint 演示文稿,然后将该演示文稿设置为变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31594476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open a PowerPoint presentation from Excel with VBA and then set that presentation to a variable
提问by ChrisG
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 MyPresentationvariable so I can reference the document I just opened.
显然还有一些额外的代码,但我试图将我刚刚在第 3 行打开的 Presentation 设置为MyPresentation变量,以便我可以引用我刚刚打开的文档。
回答by ChrisG
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)
回答by ec.v1352
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)

