PowerPoint COM Save PPT as PDF Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Stavencross
Posts: 82
Joined: 24 May 2016, 16:42

PowerPoint COM Save PPT as PDF

06 Oct 2017, 13:52

Hello! I've been trying with NO luck to save my powerpoint presentations as PDF via COM. I've searched for hours, tried a 1000 different things from the forums with no love. Everything I get returns "Type MisMatch Error"
Heres a small sample of one of my attempts.

Code: Select all

ppt :=ComObjCreate("Powerpoint.application")
ppt.Visible :=true
pptPresentation :=ppt.Presentations.Add
pptSlide :=pptPresentation.Slides.Add(1,1)
pptPresentation.ExportAsFixedFormat("C:\users\chris.miller1\desktop\test.pdf", ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputSlides, msoFalse, objPrintOptions.Ranges(1), ppPrintAll, "Slideshow Name", False, False, False, False, False)
;ppt.ActivePresentations.ExportAsFixedFormat (0,"C:\users\chris.miller1\desktop\test.pdf",0,False,false,1,1,True)
All I need to do here is save a powerpoint thru com as PDF. This will be a process I do 60 times in one sitting every month so using a GUI is out =/.
I tried in the IRC room but no one could help me. Please save my liiiifffeee!
FanaticGuru
Posts: 1403
Joined: 30 Sep 2013, 22:25

Re: PowerPoint COM Save PPT as PDF

06 Oct 2017, 15:10

Stavencross wrote:

Code: Select all

pptPresentation.ExportAsFixedFormat("C:\users\chris.miller1\desktop\test.pdf", ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputSlides, msoFalse, objPrintOptions.Ranges(1), ppPrintAll, "Slideshow Name", False, False, False, False, False)
Right off the bat all those parameters starting with pp and mso are constants that you have to look up and enter into the code as AHK does not have all those constants predefined like VBA.

PowerPoint Constants:
https://msdn.microsoft.com/en-us/librar ... e.11).aspx

There are probably other problems but that is a good start. On the plus side it is a very doable task.

It basically just involves getting a correct handle to your ActivePresentation object and that one line properly formatted and syntaxed with all the constants converted to their values. Also objPrintOptions.Ranges(1) is not valid. I would work on getting it to work with the default range before you move on to unraveling how Ranges work.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: PowerPoint COM Save PPT as PDF  Topic is solved

06 Oct 2017, 15:17

Presentation.SaveAs Method (PowerPoint)
https://msdn.microsoft.com/en-us/vba/po ... powerpoint

PpSaveAsFileType Enumeration
https://msdn.microsoft.com/en-us/librar ... e.12).aspx

Code: Select all

ppt := ComObjCreate("PowerPoint.Application")
ppt.Visible := 1
pptPresentation := ppt.Presentations.Add()
pptSlide := pptPresentation.Slides.Add(1,1)
pptPresentation.SaveAs("C:\NewFormatCopy.pdf", ppSaveAsPDF := 32)
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
Stavencross
Posts: 82
Joined: 24 May 2016, 16:42

Re: PowerPoint COM Save PPT as PDF

06 Oct 2017, 16:31

TheDewd wrote:Presentation.SaveAs Method (PowerPoint)
https://msdn.microsoft.com/en-us/vba/po ... powerpoint

PpSaveAsFileType Enumeration
https://msdn.microsoft.com/en-us/librar ... e.12).aspx

Code: Select all

ppt := ComObjCreate("PowerPoint.Application")
ppt.Visible := 1
pptPresentation := ppt.Presentations.Add()
pptSlide := pptPresentation.Slides.Add(1,1)
pptPresentation.SaveAs("C:\NewFormatCopy.pdf", ppSaveAsPDF := 32)
This works perfectly. Thank you SO SO MUCH!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, Bing [Bot], boiler, malcev, tee_rock and 122 guests