无法使用 VBA 从 Excel 打开现有的 PowerPoint 演示文稿 (2016)
Unable to open an existing PowerPoint Presentation (2016) from Excel using VBA
我尝试使用 Stack Overflow 上一个问题的代码片段,只是从使用 VBA 打开来自 Excel 的现有 PowerPoint 文件开始。示例代码片段对我不起作用。
我用的是Excel2016,参考对象模式是Microsoft Object Model 16 Library,不是前面说的Model 12。也许这就是问题的根源。我写的程序,从这个网站修改的是
Public Sub OpenPPT()
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 = "D:\Downloads\Automate_Excel\IR_Seeker_UpdateRevA.pptx"
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
End Sub
Set myPresentation
线上的套路
你应该改变
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
到
Set myPresentation = PowerPointApp.myPresentation.Open(DestinationPPT)
我还会在所有 subs 之外添加 "Option explicit" 这样如果你有一个未定义的变量它就会对你大喊大叫并纠正一些变量拼写错误。
尝试添加此行,以便您打开 PowerPoint 应用程序,在您尝试打开其中的演示文稿之前:
Set PowerPointApp = New PowerPoint.Application
打个比方:在尝试打开门之前,您需要确保您正在看建筑物...
我尝试使用 Stack Overflow 上一个问题的代码片段,只是从使用 VBA 打开来自 Excel 的现有 PowerPoint 文件开始。示例代码片段对我不起作用。
我用的是Excel2016,参考对象模式是Microsoft Object Model 16 Library,不是前面说的Model 12。也许这就是问题的根源。我写的程序,从这个网站修改的是
Public Sub OpenPPT()
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 = "D:\Downloads\Automate_Excel\IR_Seeker_UpdateRevA.pptx"
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
End Sub
Set myPresentation
线上的套路
你应该改变
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
到
Set myPresentation = PowerPointApp.myPresentation.Open(DestinationPPT)
我还会在所有 subs 之外添加 "Option explicit" 这样如果你有一个未定义的变量它就会对你大喊大叫并纠正一些变量拼写错误。
尝试添加此行,以便您打开 PowerPoint 应用程序,在您尝试打开其中的演示文稿之前:
Set PowerPointApp = New PowerPoint.Application
打个比方:在尝试打开门之前,您需要确保您正在看建筑物...