Pages

Monday, April 25, 2011

Microsoft Word printing from command line

All Testing was done using Office 2010 64bit.

Make Sure background printing is enabled in word. On the Tools menu, click Options, and then click the Print tab. Under Printing options, ensure that Background printing check box is checked.

cd C:\Program Files\Microsoft Office\Office14
winword "c:\file.BAT" /q /n /mFilePrintDefault /mFileExit

Change to the folder of your office installation.
Command Line parameters to pass to Word.

/q - Start Word without splash screen.
/n - Start Word without a document being open.
/m(MacroName) - Start Word and run the named macro. The windows macro commands FilePrintDefault and FileExit do exactly what they say. Also there is no space between the /m and the macro name.

To get a list of macros open word, on the right hand side of the View tab of the ribbon bar there s a Macros button. Click it and change the "Macros In" dropdown box to Word Commands.
Word 2010 Macros
If you need more control you can modifiy a Macro with the printing settings you need.

Create macro for the globe settings.


Sub FilePrintToPrinter1()
    ActivePrinter = "Pritner1"
    Application.PrintOut _
        FileName:="", _
        Range:=wdPrintAllDocument, _
        Item:=wdPrintDocumentWithMarkup, _
        Copies:=1, _
        Pages:="", _
        PageType:=wdPrintAllPages, _
        Collate:=True, _
        Background:=True, _
        PrintToFile:=False, _
        PrintZoomColumn:=0, _
        PrintZoomRow:=0, _
        PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
    Application.WindowState = wdWindowStateMaximize
End Sub


Now calling the this macro would be.
winword "c:\file.BAT" /q /n /mFilePrintToPrinter1 /mFileExit

Links
http://www.robvanderwoude.com/printfiles.php
http://www.autohotkey.com/forum/topic10600.html

5 comments:

  1. Very nice sharing do more like that

    ReplyDelete
  2. FYI, we were using this command for a long time, and with office 14, Word stopped quitting at the end.

    Changing it to :
    mFileCloseOrExit

    fixed the problem here ...

    ReplyDelete
  3. Thank you yfital! Couldn't figure out why Word 2010 would no longer quit after printing.

    ReplyDelete
  4. Thanks for sharing these useful tips. I've encountered several problems in printing word docs using office 2010 but, you helped me resolve those problems. I look forward to learning more about printing.

    ReplyDelete
  5. That was a nice tip about eliminating the splash screen. My next line of investigation is to completely remove any screen interaction (so this runs in an offline environment) and to have my script wait until word has finished and exited. Any ideas?

    Murray

    ReplyDelete

Please leave a comment; someone, anyone!