Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/63294587/cant-set-outputtype-for-powerpoint-print-with-vbscript

VBScript Hybrid:

<!-- : Begin batch script
@ECHO OFF
CLS

cscript //nologo "%~f0?.wsf" "FILEPATH=C:\tmp\test.pptx" "COPIES=1" "ORIENTATION=LANDSCAPE" "SLIDESPERPAGE=4" "DUPLEXSENDKEYS=True" "DUPLEXFLIPON=Short" "SLIDERANGE=1-6" //job:PPT
exit /b
PAUSE
----- Begin wsf script --->
<package>
  <job id="PPT">
    <script language="VBScript">
        Dim ObjArgs
        Set ObjArgs = wscript.arguments
        
        Dim ObjShell
        Set ObjShell = WScript.CreateObject ("WScript.shell")

        Dim DUPLEXSENDKEYS
        DUPLEXSENDKEYS= Null 
        Dim DUPLEXFLIPON
        DUPLEXFLIPON = Null
        Dim SLIDERANGE          
        SLIDERANGE = Null
        Dim COPIES
        COPIES = Null
        Dim ORIENTATION
        ORIENTATION = Null
        Dim SLIDESPERPAGE
        SLIDESPERPAGE = Null

        Dim objDictionary
        Set objDictionary = CreateObject("Scripting.Dictionary")
        For I = 0 to objArgs.Count-1
        objDictionary.CompareMode = vbTextCompare
        objDictionary.Add Split(objArgs(I), "=")(0), Split(objArgs(I), "=")(1)
        Next
       
        Dim ObjPPT
        Set ObjPPT = CreateObject("PowerPoint.Application")
        Dim objPresentation
        'Presentations.Open "filename", boolReadOnly, boolOpenUntitled, boolWithWindow
        'Open Window for Sendkeys if needed
        DUPLEXSENDKEYS = StrComp(ObjDictionary("DUPLEXSENDKEYS"), "TRUE", 1)
        DUPLEXFLIPON = StrComp(ObjDictionary("DUPLEXFLIPON"), "SHORT", 1)
        ORIENTATION = StrComp(objDictionary("ORIENTATION"), "LANDSCAPE", 1)
        If DUPLEXSENDKEYS = 0 or DUPLEXFLIPON = 0 or ORIENTATION = 0 or Not ObjDictionary("SLIDERANGE") = "" Then 
         ObjPPT.Visible = True
         Set objPresentation = ObjPPT.Presentations.Open(objDictionary("FILEPATH"))
        ELSE
         Set objPresentation = ObjPPT.Presentations.Open(objDictionary("FILEPATH"),msoTrue,,msoFalse)
        End If

        objPresentation.PrintOptions.PrintInBackground = True
        With objPresentation
         With .PrintOptions 
                .PrintInBackground = False
             If Not objDictionary("SLIDESPERPAGE") = "" Then
                'https://docs.microsoft.com/en-us/office/vba/api/PowerPoint.PpPrintOutputType
                'https://docs.microsoft.com/en-us/office/vba/api/powerpoint.printoptions.outputtype
                .OutputType = 6 'ppPrintOutputOutline	        6	Outline 
              If objDictionary("SLIDESPERPAGE") = "1" Then
                 'ppPrintOutputOneSlideHandouts	10	Single Slide Handouts
                 .OutputType = 10
              End If
              If objDictionary("SLIDESPERPAGE") = "2" Then
                 'ppPrintOutputTwoSlideHandouts	2	Two Slide Handouts
                 .OutputType = 2
              End If
              If objDictionary("SLIDESPERPAGE") = "3" Then
                 'ppPrintOutputThreeSlideHandouts	3	Three Slide Handouts
                 .OutputType = 3
              End If
              If objDictionary("SLIDESPERPAGE") = "4" Then
                 'ppPrintOutputFourSlideHandouts	8	Four Slide Handouts
                 .OutputType = 8
              End If
              If objDictionary("SLIDESPERPAGE") = "6" Then
                 'ppPrintOutputSixSlideHandouts	4	Six Slide Handouts
                 .OutputType = 4
              End If
              If objDictionary("SLIDESPERPAGE") = "9" Then
                 'ppPrintOutputNineSlideHandouts	9	Nine Slide Handouts
                 .OutputType = 9
              End If
             End If
         End With
        End With     
                  
        WScript.Sleep 500         
        ObjShell.AppActivate "PowerPoint"
        If DUPLEXSENDKEYS = 0 Then 
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "^p", TRUE ' CTRL + P [Print Screen]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%p", TRUE ' Alt + P [Print Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%d", TRUE ' Alt + d [Print Duplex Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{DOWN}", TRUE ' Down [Print Duplex Default Long]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{ENTER}", TRUE
        End If
        If DUPLEXFLIPON = 0 Then
          WScript.Sleep 500       
          ObjShell.SENDKEYS "^p", TRUE ' CTRL + P [Print Screen]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%p", TRUE ' Alt + P [Print Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%d", TRUE ' Alt + d [Print Duplex Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{DOWN}", TRUE ' Down [Print Duplex Short] 
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{ENTER}", TRUE
        End If
        If ORIENTATION = 0 Then
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "^p", TRUE ' CTRL + P [Print Screen]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%p", TRUE ' Alt + P [Print Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%o", TRUE ' Alt + d [Print Orientation Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{DOWN}", TRUE ' Down [Print Duplex Default Long]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{ENTER}", TRUE
        End If    
        If Not ObjDictionary("SLIDERANGE") = "" Then
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "^p", TRUE ' CTRL + P [Print Screen]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%p", TRUE ' Alt + P [Print Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%s", TRUE ' Alt + d [Print Slides Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS ObjDictionary("SLIDERANGE"), TRUE ' Down [Print Duplex Default Long]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{ENTER}", TRUE    
        End If
        If ObjDictionary("COPIES") > 1 Then
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "^p", TRUE ' CTRL + P [Print Screen]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%p", TRUE ' Alt + P [Print Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "%n", TRUE ' Alt + n [Print Copies Options]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS ObjDictionary("Copies"), TRUE ' Down [Print Duplex Default Long]
          WScript.Sleep 1000       
          ObjShell.SENDKEYS "{ENTER}", TRUE            
        End If 
         
        If DUPLEXSENDKEYS = 0 or DUPLEXFLIPON = 0 or ORIENTATION = 0 or Not ObjDictionary("SLIDERANGE") = "" Then
         WScript.Sleep 1000       
         ObjShell.SENDKEYS "^p", TRUE ' CTRL + P [Print Screen]
         WScript.Sleep 1000       
         ObjShell.SENDKEYS "%p", TRUE ' Alt + P [Print Options]
         WScript.Sleep 1000       
         ObjShell.SENDKEYS "%p", TRUE ' Alt + n [Print]
         WScript.Sleep 4200 
        ELSEIf Not ObjDictionary("COPIES") = "" Then
         '.PrintOut (From[Integer], To[Integer], PrintToFile[String], Copies [Integer], Collate[Bool]{msoTrue/False})  
         Call ObjPresentation.PrintOut( , , ,ObjDictionary("COPIES"),TRUE)
        ELSE
         ObjPresentation.PrintOut
        End If
        
        ObjPresentation.PrintOptions.PrintInBackground = True         

        ObjPresentation.Saved = TRUE
        ObjPPT.Quit
        Set FPath = Nothing
        Set ObjFS = Nothing
        Set ObjPPT = Nothing
        Set ObjArgs = Nothing
        Set objDictionary = Nothing
        Set ObjShell = Nothing
    </script>
  </job>
</package>

Note: I found the /P switch just printed for me, no Dialogue.

https://smallbusiness.chron.com/run-powerpoint-command-line-39714.html

"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE" /PT "EPSON60798C (WF-2630 Series)"  "" "" "C:\tmp\test.pptx"
::powerpnt.exe" /PT "PrinterName" "" "" "MyFile.pptx"
/B: Launches PowerPoint with a new blank presentation.

Example: "powerpnt.exe /b

/C: Launches PowerPoint with the specified file and also opens Microsoft Windows NetMeeting conferencing.

Example: powerpnt.exe /C C:\Users\YourName\Documents\netmeetingfile.pptx

/EMBEDDING: Launches PowerPoint without showing you the Office PowerPoint program window. This is usually used by developers when testing add-ins.

Example: powerpnt.exe /EMBEDDING

/M: This switch runs a macro in a specified presentation file.

Example: powerpnt.exe /M C:\Users\YourName\Documents\test.pptx MyMacro

In this example, the macro "MyMacro" is used in the test.pptx file.

/N: Opens PowerPoint and creates a new presentation based on a template you specify.

Example: powerpnt.exe /N Path\customtemplate.potx

In this example, "Path" represents the template's location.

/O: Launches PowerPoint and specifies a list of files to open, rather than just one.

Example: powerpnt.exe" /O File presntation1.pptx, File presentation2.pptx

/P: This print switch prints the presentation to your default printer. The print dialog box opens.

Example: powerpnt.exe /p MyFile.pptx

/PT: This print-to switch prints the presentation to a printer you specify without opening a dialog box.

Example: powerpnt.exe" /PT "PrinterName" "" "" "MyFile.pptx"

Note that you should include the empty quotation marks.

/RESTORE: If PowerPoint crashed, you can use this switch to restore PowerPoint to the way it was before it closed. PowerPoint will attempt to restore the presentation you were working on.

Example: powerpnt.exe /RESTORE

/S: This switch opens a file you specify as a slide show.

Example: powerpnt.exe /S C:\Users\YourName\Documents\show.pptx
  • No labels