如何获取 Excel VBA 中打开的 powerpoint 演示文稿的处理程序

the*_*rug 4 excel powerpoint vba

我正在尝试获取 Powerpoint 演示文稿的处理程序。通常,我使用以下指令:

Set pres = PowerPoint.application.Presentations(pptFile)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

“activex 组件无法创建对象”

pptFile 应该已经打开

任何想法?

Ste*_*erg 5

如果您不想打开同一个演示文稿两次,请执行以下操作:

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
Run Code Online (Sandbox Code Playgroud)