Function Reference


_Word_DocPrint

Prints all or parts of the specified document

#include <Word.au3>
_Word_DocPrint ( $oDoc [, $bBackground = False [, $iCopies = 1 [, $iOrientation = -1 [, $bCollate = True [, $sPrinter = "" [, $iRange = $WdPrintAllDocument [, $vFrom = 0 [, $vTo = 0 [, $sPages = "" [, $iPageType = $WdPrintAllPages [, $iItem = $WdPrintDocumentContent]]]]]]]]]]] )

Parameters

$oDoc Word document object
$bBackground [optional] True lets the script continue while the document is printed (default = False)
$iCopies [optional] The number of copies to be printed (default = 1)
$iOrientation [optional] Sets the orientation of the page:
    -1 - Use current document orientation (default)
    0 - Portrait ($WdOrientPortrait of the WdOrientation enumeration)
    1 - Landscape ($WdOrientLandscape of the WdOrientation enumeration)
$bCollate [optional] True prints all pages of the document before printing the next copy (default = True)
$sPrinter [optional] Sets the name of the printer (default = "" = Active printer)
$iRange [optional] Specifies the page range to print.
Can be any of the WdPrintOutRange enumeration.
(default = $WdPrintAllDocument = print the entire document)
$vFrom [optional] The starting page number (integer) when $iRange is set to $WdPrintFromTo
$vTo [optional] The ending page number (integer) when $iRange is set to $WdPrintFromTo
$sPages [optional] The page numbers and page ranges to be printed, separated by commas when $iRange is set to 4.
For example, "2, 6-10" prints page 2 and pages 6 through 10 (default = "")
$iPageType [optional] The type of pages to be printed. Can be any of the WdPrintOutPages enumeration
(default = $WdPrintAllPages = print all pages)
$iItem [optional] The item to be printed. Can be any of the WdPrintOutItem enumeration
(default = $WdPrintDocumentContent = document content)

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - $oDoc is not an object
2 - Error setting page orientation. @extended is set to the COM error code
3 - @error returned when setting the active printer to $sPrinter
4 - Error occurred when printing the file. @extended is set to the COM error code

Remarks

Specifying $bBackground does NOT pause the script until the document is finished printing, it only pauses
until Microsoft Word finishes sending the document to the printer.
If you specify a printer note that the \\servername\printer seems to be case sensitive.

Related

_Word_DocExport

Example

#include <MsgBoxConstants.au3>
#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPrint Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPrint Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; *****************************************************************************
; Print the complete document with default values
; *****************************************************************************
Local $sActivePrinter = $oDoc.Application.ActivePrinter
MsgBox($MB_SYSTEMMODAL, "", "The name of the active printer is: " & $sActivePrinter)
_Word_DocPrint($oDoc)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPrint Example", _
        "Error printing the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPrint Example", "The document has successfully been printed to: " & _
        $sActivePrinter)