如何在Excel VBA中获取已打开powerpoint演示文稿的处理程序
我正在尝试获取powerpoint演示文稿的处理程序。通常,我使用以下说明:如何在Excel VBA中获取已打开powerpoint演示文稿的处理程序,excel,vba,powerpoint,Excel,Vba,Powerpoint,我正在尝试获取powerpoint演示文稿的处理程序。通常,我使用以下说明: Set pres = PowerPoint.application.Presentations(pptFile) 我收到以下错误消息: “activex组件无法创建对象” PPT文件应该已经打开 有什么想法吗?如果您不想打开同一演示文稿两次,请执行以下操作: Dim pptFile As String pptFile = "C:\Users\" & Environ$("username") & "\D
Set pres = PowerPoint.application.Presentations(pptFile)
我收到以下错误消息:
“activex组件无法创建对象”
PPT文件应该已经打开
有什么想法吗?如果您不想打开同一演示文稿两次,请执行以下操作:
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)
如果文件未打开,Automation将打开该文件;如果文件已打开,Automation将不会再次打开该文件。谢谢Steve。好主意!