# Function Reference

# _Excel_Print

Prints a workbook, worksheet, chart or range

#include <Excel.au3>
_Excel_Print ( $oExcel, $vObject [, $iCopies = Default [, $sPrinter = Default [, $bPreview = Default [, $iFrom = Default [, $iTo = Default [, $bPrintToFile = Default [, $bCollate = Default [, $sPrToFileName = ""]]]]]]]] )

## Parameters

$oExcel | Excel application object
$vObject | Workbook, worksheet, chart or range object to print. Range can be specified as A1 range too
$iCopies | [optional] Number of copies to print (default = keyword Default = 1)
$sPrinter | [optional] Name of the printer to be used. Defaults to active printer (default = keyword Default)
$bPreview | [optional] True to invoke print preview before printing (default = keyword Default = False)
$iFrom | [optional] Page number where to start printing (default = keyword Default = first page)
$iTo | [optional] Page number where to stop printing (default = keyword Default = last page)
$bPrintToFile | [optional] True to print to a file. See parameter $sPrToFileName (default = keyword Default = False)
$bCollate | [optional] True to collate multiple copies (default = keyword Default = False)
$sPrToFileName | [optional] If $bPrintToFile is set to True, this argument specifies the name of the file you want to print to.

## Return Value

Success: | the object of the printed range.
Failure: | 0 and sets @error.
@error: | 1 - $oExcel is not an object or not an application object 2 - $vObject is not an object or an invalid A1 range. @error is set to the COM error code 3 - Error printing the object. @extended is set to the COM error code

## Related

_Excel_Export

## Example

### Example 1

    #include "Extras\HelpFileInternals.au3"

    #include <Excel.au3>
    #include <MsgBoxConstants.au3>

    ; Create application object and open an example workbook
    Local $oExcel = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oExcel, _Extras_PathFull("_Excel4.xls"), True)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example", "Error opening workbook '" & _Extras_PathFull("_Excel4.xls'.") & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

    ; Print range A1:B3 of the active worksheet to the default printer.
    _Excel_Print($oExcel, "A1:B3")
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 1", "Error printing cells." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 1", "Range successfully printed.")

### Example 2

    #include "Extras\HelpFileInternals.au3"

    #include <Excel.au3>
    #include <MsgBoxConstants.au3>

    ; Create application object and open an example workbook
    Local $oExcel = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oExcel, _Extras_PathFull("_Excel4.xls"), True)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example", "Error opening workbook '" & _Extras_PathFull("_Excel4.xls'.") & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

    ; Print the active worksheet to the default printer.
    _Excel_Print($oExcel, $oExcel.ActiveSheet)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 2", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 2", "Active Worksheet successfully printed.")

### Example 3

    #include "Extras\HelpFileInternals.au3"

    #include <Excel.au3>
    #include <MsgBoxConstants.au3>

    ; Create application object and open an example workbook
    Local $oExcel = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oExcel, _Extras_PathFull("_Excel4.xls"), True)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example", "Error opening workbook '" & _Extras_PathFull("_Excel4.xls'.") & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

    ; Print a complete workbook to the default printer.
    _Excel_Print($oExcel, $oWorkbook)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 3", "Error printing workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Print Example 3", "Workbook successfully printed.")