[英]Error while opening existing PowerPoint file through Excel VBA
I am using the following code for opening a new PowerPoint presentation but it gives an error which I am not able to figure out the solution of. 我正在使用以下代码打开一个新的PowerPoint演示文稿,但它给出了一个错误,我无法找出解决方案。
strPresPath = "C:\Users\MAHE\Documents\template.ppt"
Set oPPTApp = CreateObject("PowerPoint.Application")
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
and the error being 错误是
"Method 'open' of object 'Presentation' failed"
Also if any one can help in adding new slide to the PowerPoint would be of great help. 另外,如果有人可以帮助向PowerPoint中添加新幻灯片,也将有很大帮助。
I don't see a problem in the code. 我在代码中没有看到问题。 But you could try using a reference to "Microsoft PowerPoint XX.X Object Library":
但是您可以尝试使用对“ Microsoft PowerPoint XX.X对象库”的引用:
The code would be like this instead: 代码将如下所示:
Dim oPPTApp As New PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
In addition to @gizlmeier's suggestion, try this: 除了@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
That'll at least prove that the PPT object has been created successfully (or that it hasn't been). 至少可以证明PPT对象已成功创建(或尚未创建)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.