2016-07-07 152 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對象已成功創建(或者它沒有)。