繁体   English   中英

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

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

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

Set pres = PowerPoint.application.Presentations(pptFile)

我收到以下错误消息:

'一个activex组件无法创建对象'

pptFile应该已经打开了

任何的想法?

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

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

您也可以尝试以下命令:

Set pres = GetObject(pptFile)

如果文件未打开,自动化将打开该文件,如果该文件已经打开,它将不会再次打开该文件。

暂无
暂无

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

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