Prasath Kv
Prasath Kv

Reputation: 31

How to open Powerpoint using VBA

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)

Upvotes: 3

Views: 8438

Answers (1)

0m3r
0m3r

Reputation: 12495

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

Upvotes: 2

Related Questions