I am able to open a pptx file via vbscript and print it, but I can't for the life of me get the OutputType
set. I continuallly get this error no matter my formatting, I even copied direct from Microsoft docs. Any idea whats wrong?>
https://learn.microsoft.com/en-us/office/vba/api/powerpoint.printoptions
Error:
C:\Windows\system32>cscript.exe C:\tmp\print_ppt.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
C:\tmp\print_ppt.vbs(26, 9) Microsoft PowerPoint 2016: PrintOptions.OutputType : Invalid enumeration value.
Code:
Dim objPPT
Dim objPresentation
Dim objPrintOptions
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
'Presentations.Open "filename", boolReadOnly, boolOpenUntitled, boolWithWindow
Set objPresentation = objPPT.Presentations.Open("C:\tmp\test.pptx",msoTrue,,msoFalse)
Set objPrintOptions = objPresentation.PrintOptions
objPrintOptions.PrintInBackground = False
'https://learn.microsoft.com/en-us/office/vba/api/powerpoint.printoptions.outputtype
'objPrintOptions.OutputType = ppPrintOutputSixSlideHandouts
'objPresentation.PrintOut
With objPresentation
With .PrintOptions
.NumberOfCopies = 2
.Collate = False
.PrintColorType = ppPrintColor
.PrintHiddenSlides = True
.FitToPage = True
.FrameSlides = True
.OutputType = ppPrintOutputSlides
End With
.PrintOut
End With
objPresentation.PrintOptions.PrintInBackground = True
objPPT.Quit
Set objPPT = nothing
VBA and VBScript are similar obviously, but different. This was a good read for me tonight to start seeing some of the "minor" differences which can give you a headache if you are familiar w/ VBA and expect VBScript to work the same.
Specifcally the part about how VBScript does not support named arguments.
This is a similar situation where the propertity will work with VBScript, but the sytax in VBA has multiple options and only one in VBScript will work.
In this case it was using the numerical value.
Another example is my line w/
'Presentations.Open "filename", boolReadOnly, boolOpenUntitled, boolWithWindow
Set objPresentation = objPPT.Presentations.Open("C:\tmp\test.pptx",msoTrue,,msoFalse)
This is using positional
arguments vs named
value pairs.
Here is where I found the numerical version for the option, now to script some logic into my script so end users can pass an argument like 4
and expect 4Slides/Page
.
https://learn.microsoft.com/en-us/office/vba/api/PowerPoint.PpPrintOutputType
With objPresentation
With .PrintOptions
.PrintInBackground = False
'https://learn.microsoft.com/en-us/office/vba/api/PowerPoint.PpPrintOutputType
'https://learn.microsoft.com/en-us/office/vba/api/powerpoint.printoptions.outputtype
.OutputType = 8
End With
'.PrintOut
.PrintOptions.PrintInBackground = True
End With