How to get the handler of an opened powerpoint presentation in Excel VBA

excel, powerpoint, vba

Solution

If you don't want to open the same presentation twice, something like this:

Dim pptFile As String
pptFile = "C:\Users\" & Environ$("username") & "\Desktop\ppp.pptx"

Dim pptApp As PowerPoint.Application
Set pptApp = New PowerPoint.Application

Dim pres As Presentation

For Each pres in pptApp.Presentations
   If pres.FullName = pptFile then
      ' found it!
      Exit For
   End If
End If

' And possibly do this to open the file if it's not already open
If pres Is Nothing Then
   Set pres = pptApp.Presentations.Open(pptFile)
End If

Problem

I am trying to get the handler of a powerpoint presentation. Typically, I use the following instruction: ``` Set pres = PowerPoint.application.Presentations(pptFile) ``` I get the following error message: 'an activex component can't create object' pptFile is supposed to be already open Any Idea?

Original source