3
votes

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
You've made certain that the value in pptpath is correctly formatted and that the file's where you say it is, I'll assume. But is the file password protected and are you certain it's not corrupt? Can you doubleclick the file to open in in PPT w/o any errors?Steve Rindsberg

1 Answers

2
votes

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