How to open Powerpoint using VBA

亡梦爱人 提交于 2019-12-11 03:57:54

问题


I am trying to open a PowerPoint file through Excel VBA.

I get

run-time error -2147467259 (80004005)
method 'open' of object 'Presentation Failed'

This is the code

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

It shows the error on

Set PPpres = PP.Presentations.Open(pptpath)

回答1:


Try This

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

Or make sure you set references Microsoft PowerPoint Object Library

Step 1

Step 2

More about object

I strongly recommend to use Option Explicit at the start of your VBA code



来源:https://stackoverflow.com/questions/30148410/how-to-open-powerpoint-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!