如何获得在Excel VBA中打开的PowerPoint演示文稿的处理程序

我正在试图获得一个幻灯片演示文稿的处理程序。 通常,我使用以下指令:

Set pres = PowerPoint.application.Presentations(pptFile) 

我收到以下错误信息:

'一个ActiveX组件不能创build对象'

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) 

如果文件没有打开,自动化将打开文件,如果文件已经打开,它将不会再打开文件。