0

I am calling VBA code from an Excel spreadsheet to open an existing PowerPoint file via the Presentations.Open method. In my environment I developed via Early Binding using the MS PowerPoint 14.0 Object Library and the codes run without a problem.

However, when the script was called in another machine that runs MS Office 2013 (i.e. MS PowerPoint 15.0 Object Library), a Run-time error pops up

Method 'Open' of object 'Presentations' failed

Is the Presentations.Open method deprecated in PPT 15.0 Object library? I tried searching Internet but couldn't find documentation on the change.

I also attempted to use Late Binding to see if it works, but received the same error.

Please find below the code snipnets I used (early + late binding).

Thank you very much for the help.


Early Binding Code Snipnet

Sub EarlyBinding()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

Dim PowerpointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation

Set PowerpointApp = New PowerPoint.Application
PowerpointApp.Visible = True

Dim myPath As String
myPath = ws.Range("wk_dir").Value & "\" & ws.Range("ppt_name").Value

Set myPresentation = PowerpointApp.presentations.Open(myPath)
myPresentation.SaveAs (ws.Range("wk_dir").Value & "\test_earlybind.pptx")

Set myPresentation = Nothing
Set PowerpointApp = Nothing
End Sub

Late Binding Code Snipnet

Sub LateBinding()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

Dim PowerpointApp As Object
Dim myPresentation As Object

Set PowerpointApp = CreateObject("Powerpoint.Application")
PowerpointApp.Visible = True

Dim myPath As String
myPath = ws.Range("wk_dir").Value & "\" & ws.Range("ppt_name").Value

Set myPresentation = PowerpointApp.presentations.Open(myPath)

myPresentation.SaveAs (ws.Range("wk_dir").Value & "\test_latebind.pptx")

Set myPresentation = Nothing
Set PowerpointApp = Nothing
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
denwong1129
  • 75
  • 1
  • 5
  • Are you sure the path is correct for the other machine? – Rory Jan 30 '18 at 16:16
  • 1
    `debug.print myPath` and what comes up? – dwirony Jan 30 '18 at 16:38
  • A) Presentations.Open is supported in pretty much any version of Windows PowerPoint back to Office 97 and on any Mac version that includes VBA. B) You'd get a "Method or Data Member not found" error message if you called an unsupported method. As the others have suggested, verify that the file you're trying to open actually exists. – Steve Rindsberg Jan 30 '18 at 17:07
  • Does this happen for any given file? Or is it perhaps that you locked it somehow? – Sam Jan 30 '18 at 17:17
  • Tried Debug.Print before, it is indeed a valid path. If a file is simply not found, there is a run-time error "PowerPoint could not open the file". Not the case here though – denwong1129 Jan 30 '18 at 17:52

1 Answers1

0

presentations.Open() may fail if you pass a relative path as parameter. The reason is that PowerPoint uses its own working directory which is usually different from the working directory of the calling application.

The solution is to pass an absolute path rather than a relative one.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54