如何使用VBA打开Powerpoint

时间:2015-05-10 06:29:18

标签: excel vba powerpoint-vba

我正在尝试通过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

1 个答案:

答案 0 :(得分: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代码的开头使用Option Explicit