[英]Error while opening existing PowerPoint file through 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中添加新幻燈片,也將有很大幫助。
我在代碼中沒有看到問題。 但是您可以嘗試使用對“ Microsoft PowerPoint XX.X對象庫”的引用:
代碼將如下所示:
Dim oPPTApp As New PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
除了@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對象已成功創建(或尚未創建)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.