2016-07-07 146 views
0

我使用以下代码打开新的PowerPoint演示文稿,但它提供了一个错误,我无法找出解决方案。通过Excel VBA打开现有PowerPoint文件时出现错误

strPresPath = "C:\Users\MAHE\Documents\template.ppt" 
Set oPPTApp = CreateObject("PowerPoint.Application") 
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath) 

和错误是

"Method 'open' of object 'Presentation' failed" 

此外,如果任何人可以在添加新幻灯片PowerPoint演示将是很大的帮助帮助。

回答

0

我在代码中看不到问题。但是,你可以尝试使用一提到“微软的PowerPoint XX.X对象库”:

的代码会是这样,而不是:

Dim oPPTApp As New PowerPoint.Application 
Dim ppPres As PowerPoint.Presentation 

Set oPPTFile = oPPTApp.Presentations.Open(strPresPath) 
0

除了@ gizlmeier的建议,试试这个:

strPresPath = "C:\Users\MAHE\Documents\template.ppt" 
Set oPPTApp = CreateObject("PowerPoint.Application") 

' Verify that the PPT object was created successfully 
If oPPTApp is Nothing Then 
    MsgBox "Unable to create PowerPoint object" 
    Exit Sub ' or function 
Else 
    Set oPPTFile = oPPTApp.Presentations.Open(strPresPath) 
End if 

这至少会证明PPT对象已成功创建(或者它没有)。