简体   繁体   English

无法使用 VBA 从 Excel 打开现有的 PowerPoint 演示文稿 (2016)

[英]Unable to open an existing PowerPoint Presentation (2016) from Excel using VBA

I have tried to use a code snippet from a previous question on Stack Overflow just starting with opening an existing PowerPoint file from Excel using VBA.我尝试使用 Stack Overflow 上一个问题的代码片段,刚开始使用 VBA 从 Excel 打开现有 PowerPoint 文件。 The example code snippet will not work for me.示例代码片段对我不起作用。

I am using Excel 2016, and the reference object mode is Microsoft Object Model 16 Library, not the Model 12 referred to earlier. I am using Excel 2016, and the reference object mode is Microsoft Object Model 16 Library, not the Model 12 referred to earlier. Maybe this is the source of the problem.也许这就是问题的根源。 The procedure I wrote, modified from this site was我写的,从这个网站修改的程序是

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

The routine gags on the Set myPresentation line Set myPresentation线上的常规噱头

Try adding this line, so that you open the PowerPoint Application, before you try to open the Presentation in it:尝试添加此行,以便在尝试在其中打开演示文稿之前打开 PowerPoint 应用程序:

Set PowerPointApp = New PowerPoint.Application

As an analogy: you need to make sure that you are looking at a building before you try to open the door...打个比方:在尝试开门之前,您需要确保自己正在看一座建筑物……

You should change你应该改变

Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)

To

Set myPresentation = PowerPointApp.myPresentation.Open(DestinationPPT)

I would also add "Option explicit" outside of all the subs so it will yell at you if you have a undefined variable as well as correct some variable typos.我还会在所有 subs 之外添加“选项显式”,这样如果你有一个未定义的变量以及更正一些变量拼写错误,它就会对你大喊大叫。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM