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. 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. 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
Try adding this line, so that you open the PowerPoint Application, before you try to open the Presentation in it:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.