Using COM for PowerPoint

Post your working scripts, libraries and tools
Posts: 5
Joined: 18 Apr 2017, 14:39
GitHub: JulesverneOnGitHub

Using COM for PowerPoint

16 Apr 2018, 17:04

I took some time this weekend to try and demystify COM a little by rewriting a working vbscript for PowerPoint into ahk. I know I'm not the only one that freaks out a little when it comes to COM however I am in love with the advantages of it.

First I'll give the widely used internet vbscript (.vbs) by @BillP3rd that exports PowerPoint to PDF. This script is different from .SaveAs method as it allows options to PDF rather than just a strict page by page PDF. For example you can have the PDF output show 1,2,3,4,5,6 slides per PDF page. If you just want to do a simple SaveAs to PDF with no options you can find the ahk code here:

You can access the different options by paying attention to the Constants (Const) in the vbscript. Constants are simply variables that don't change, but their values are numbers, and so it's easier to use variables for human eyes. The script below creates a PDF of 2 slides per page of all the pages.

To use this code, save the file as ppttopdf.vbs. open up a command prompt and type in cscript //nologo %pathtofolder%\ppttopdf.vbs "%pathandfilenameOfPPTfile%" "%pathtosavetoandfilenametoSaveAsPDF%" replace pathtofolder and pathandfilenameOfPPTfile pathtosavetoandfilenametoSaveAsPDFto your file.
ex. cscript //nologo C:\Test\ppttopdf.vbs "C:\Test\file.PPTX" "C:\Test\file.pdf"

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Things to keep in mind about the difference between ahk and vb(s):

    1.)ahk does not use Const variables, however in my research @kon on this board came up with a Microsoft Office Const library here: I have not used it so I can't provide insight on it. But for the purposes of this script we won't need it.
    2.)ahk does not Dim variables. Dim is just declaring variables. vbscript needs to know what variables you will use, if you want to use them globally in different subroutines, functions, etc.
    3.)option explicit in vbscript is related to the Dim command so again, is unnecessary in the ahk script. If there is an equivalent to it in ahk, I do not know what it is.

So below is the ahk script. The ahk code itself is written below the vbs code (commented out) and some additional (also commented out) so you can get a good visual as to how to rewrite vbscript to COM for ahk. It's pretty similar code in some circumstances. One thing to keep in mind is that COM code is written as expressions in ahk.

Run this script like the vbscript. Save this script as PPTtoPDF.ahk %pathtofolder%\PPTtoPDF.ahk "%pathandfilenameOfPPTfile%" "%pathtosavetoandfilenametoSaveAsPDF%" replace pathtofolder and pathandfilenameOfPPTfile pathtosavetoandfilenametoSaveAsPDFto your file.
ex. C:\Test\PPTtoPDF.ahk "C:\Test\file.PPTX" "C:\Test\file.pdf"

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Please feel free to comment. Make improvements. Suggestions. Questions. Hope this is helpful to someone.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: arcticir, w0z and 21 guests