Print to PDF from PowerPoint - VBA Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
SirSocks
Posts: 243
Joined: 26 Oct 2018, 08:14

Print to PDF from PowerPoint - VBA

21 Jan 2021, 16:17

Hello,
Question: How can powerpoint print to pdf using VBA?

I'm trying to get PowerPoint to print to pdf. I keep getting errors.
This is the error that is thrown....
Image

I've been using this as a reference document: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.exportasfixedformat

Code: Select all

#NoEnv  
SendMode Input
#SingleInstance Force
;####
; NOTE: You must open PowerPoint first.
;####
OutputFile := "C:\test.pdf" ; save location.
ppt := ComObjActive("Powerpoint.Application")
ppt.ActivePresentation.ExportAsFixedFormat( OutputFile, ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoCTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputBuildSlides, msoFalse, , , , False, False, False, False, False)
return
All help is appericated,
Thank you.
gregster
Posts: 5814
Joined: 30 Sep 2013, 06:48

Re: Print to PDF from PowerPoint - VBA

21 Jan 2021, 17:01

I don't know anything about Office COM interfaces.
But what are ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoCTrue and so on supposed to be? Variables, strings or VBA constants ?

Currently, they are not strings and not defined as variables anywhere in your code, afaics, and AHK will most likely handle them as random empty, unassigned variables - but I assume that they are actually supposed to hold some (constant) value instead (compare https://docs.microsoft.com/de-de/office/vba/api/powerpoint.ppfixedformattype), like 2, eg.

I also assume that the OutputFile variable is supposed to hold a string: OutputFile := "C:\test.pdf" Edit: Oh, already fixed :thumbup: .
User avatar
SirSocks
Posts: 243
Joined: 26 Oct 2018, 08:14

Re: Print to PDF from PowerPoint - VBA

21 Jan 2021, 17:37

@gregster Some values in VBA are Constants. The values that you mentioned are constant values.
ppFixedFormatTypePDF and ppFixedFormatIntentScreen.
However, I'm obviously doing something wrong because I can get it working 🤔.

I was under the impression that everything inside the brackets (......) would be directly interpreted by PowerPoint. But I could very well be wrong on this.

Hopefully someone can weigh in with some guidance on this error.
gregster
Posts: 5814
Joined: 30 Sep 2013, 06:48

Re: Print to PDF from PowerPoint - VBA

21 Jan 2021, 17:50

I was under the impression that everything inside the brackets (......) would be directly interpreted by PowerPoint.
I doubt it.

I would try to replace these constant names with the respective constant values, like 2 in the case of ppFixedFormatTypePDF (according to the MS docs that I linked to) - or assign these variables/values before you use them. Did you try that already?

Edit: you could also try to use quote marks around the constant names, if the numeric values don't work.
FanaticGuru
Posts: 1496
Joined: 30 Sep 2013, 22:25

Re: Print to PDF from PowerPoint - VBA

21 Jan 2021, 18:02

SirSocks wrote:
21 Jan 2021, 17:37
I was under the impression that everything inside the brackets (......) would be directly interpreted by PowerPoint. But I could very well be wrong on this.

You are very well wrong on this.

You have to put the values of those VBA constants. VBA basically has a table of all those variables where it looks up the values. PowerPoint is expecting actual values not the names of undefined variables. ppFixedFormatTypePDF is just a constant variable in VBA.

You could create a huge table and define all the VBA constants and then you could use the constants the same way VBA does. It is not really worth all the work to define the 100s and 100s of constants that COM uses. Best just to define the few you need or skip the variables all together and put the values in their place.

ppt.ActivePresentation.ExportAsFixedFormat( ... ) is basically just a function call. You got to pass it the correct values.

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
SirSocks
Posts: 243
Joined: 26 Oct 2018, 08:14

Re: Print to PDF from PowerPoint - VBA

21 Jan 2021, 18:26

All this information is great 😀.
Thank you very much @gregster @FanaticGuru and @boiler
This is extremely helpful!
FanaticGuru
Posts: 1496
Joined: 30 Sep 2013, 22:25

Re: Print to PDF from PowerPoint - VBA

21 Jan 2021, 19:03

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

Return to “Ask For Help”

Who is online

Users browsing this forum: DataLife, djuga, Google [Bot], swrong, try_else_finally, Xeo786 and 35 guests