Chr*_*isG 1 excel powerpoint vba excel-vba powerpoint-vba
我必须将大量Excel图表发布到特定的PowerPoint文档中,然后在Excel VBA中构建一个宏来为我完成.
我能够正确地打开我想要更新的PowerPoint演示文稿,但是我不知道如何设置我刚刚打开的演示文稿到一个名为的变量MyPresentation.
Dim myPresentation As PowerPoint.Presentation
Dim PowerPointApp As PowerPoint.Application
PowerPointApp.Presentations.Open Filename:="obscured filepath and name"`
Run Code Online (Sandbox Code Playgroud)
显然还有一些额外的代码,但我正在尝试将我刚刚在第3行设置的Presentation设置为MyPresentation变量,这样我就可以引用刚刚打开的文档了.
我最终找到了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"`
Run Code Online (Sandbox Code Playgroud)
查看Spreadsheet Guru从Excel VBA打开PPT的指南
然后:
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
Run Code Online (Sandbox Code Playgroud)
First you have to pave the way for using ppt files, what I did:
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)
Run Code Online (Sandbox Code Playgroud)