2015-05-10 111 views
2

我想通过Excel VBA打开Powerpoint端。但我得到以下运行时错误无法使用VBA打开Powerpoint

运行时错误-2147467259(80004005) 方法对象的“开放”“演示失败”

这是代码我试图

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 

它显示在下面的代码 集PPpres误差= PP.Presentations.Open(pptpath)

预先感谢

+0

你已经取得了一定的,在pptpath值格式正确,在那里你说该文件的我会假设的。但是,文件密码是否受到保护,您确定它没有损坏?你可以双击文件打开在PPT W/O任何错误? –

+0

它为你工作。 – 0m3r

回答

1

试试这个

Set PP = CreateObject("PowerPoint.Application") 
Set PPpres = PP.Presentations.Open(pptpath) 
PP.Visible = msoCTrue 

,或者确保您设置引用的Microsoft PowerPoint对象库

步骤1

enter image description here

步骤2

enter image description here

More about object

我强烈建议使用显式的选项在您的VBA代码的开始