我正在尝试通过Excel VBA打开PowerPoint文件。
我得到了
运行时错误-2147467259(80004005)
方法' open'对象'演示文稿失败'
这是代码
vendor/yiisoft/yii2/messages
它显示错误
Sub createPPT(data As Workbook, ByVal pptpath As String)
Dim Sh As Shape
Dim PP As Object
Dim PPpres As Object
'Create a PP application and make it visible
Set PP = New PowerPoint.Application
PP.Visible = msoCTrue
Set PPpres = PP.Presentations.Open(pptpath)
Set Sh = data.Worksheets("Overall_Role").Shapes("Chart 3")
Sh.Copy
PPpres.Slides(6).Shapes.Paste
Set Sh = Nothing
Set PP = Nothing
Set PPpres = Nothing
End Sub
答案 0 :(得分:1)
试试这个
Set PP = CreateObject("PowerPoint.Application")
Set PPpres = PP.Presentations.Open(pptpath)
PP.Visible = msoCTrue
或确保设置引用Microsoft PowerPoint对象库
第1步
第2步
我强烈建议您在VBA代码的开头使用Option Explicit