Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 792
mStudent Avatar asked Oct 28 '25 07:10

mStudent


1 Answers

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
like image 73
Steve Rindsberg Avatar answered Oct 29 '25 21:10

Steve Rindsberg