Home » excel » excel – How to open Powerpoint using VBA

excel – How to open Powerpoint using VBA

Posted by: admin April 23, 2020 Leave a comment

Questions:

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)
How to&Answers:

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

enter image description here

Step 2

enter image description here

More about object

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