Reputation: 21
I am trying to generate a PDF file from a PowerPoint file. This should all be done from clicking a button in an Excel file with a VBA script. So far I have managed to write the code below. It opens the PowerPoint file correctly, but also displays the error: "Object doesn't support this property or method".
strPath = "Q:\X\Test.pptx"
Set objApp = CreateObject("Powerpoint.Application")
objApp.Visible = True 'False or True
Set wbToRun = objApp.Presentations.Open(strPath)
wbToRun.ExportAsFixedFormat "<Q:\X\1.pdf>", ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoCTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputBuildSlides, msoFalse, , , , False, False, False, False, False
objApp.DisplayAlerts = False
wbToRun.Close
objApp.Quit
Hope you are able to help on where I went wrong. Thank you.
Upvotes: 1
Views: 331
Reputation: 2828
I was able to reproduce your errors. The following solution worked for me. Make sure you have enabled your reference to the Microsoft Powerpoint Object Library.
Sub ppttest5()
Dim savePath As String
Dim AppPowerPoint
Dim wbToRun
Set AppPowerPoint = CreateObject("PowerPoint.Application")
'Location of saved file
savePathFN = "C:\mydirb\test.pdf" 'change as per your path
AppPowerPoint.Visible = True
Set wbToRun = AppPowerPoint.Presentations.Open("C:\mydirb\Test.pptx") 'change location of file path
wbToRun.SaveAs savePathFN, ppSaveAsPDF
wbToRun.Close
AppPowerPoint.Quit
Set OpenPresentation = Nothing
Set AppPowerPoint = Nothing
End Sub
Upvotes: 1