# Function Reference

# _Excel_Export

Exports a workbook, worksheet, chart or range as PDF or XPS

#include <Excel.au3>
_Excel_Export ( $oExcel, $vObject, $sFileName [, $iType = $xlTypePDF [, $iQuality = $xlQualityStandard [, $bIncludeProperties = True [, $iFrom = Default [, $iTo = Default [, $bOpenAfterPublish = Default]]]]]] )

## Parameters

$oExcel | Excel application object
$vObject | Workbook, worksheet, chart or range object to export as PDF or XPS. Range can be specified as A1 range too
$sFileName | Path/name of the exported file
$iType | [optional] Can be either $xlTypePDF or $xlTypeXPS of the XlFixedFormatType enumeration (default = $xlTypePDF)
$iQuality | [optional] Can be any of the XlFixedFormatQuality enumeration (default = $xlQualityStandard)
$bIncludeProperties | [optional] True indicates that document properties should be included (default = True)
$iFrom | [optional] The page number at which to start publishing (default = keyword Default = start at the beginning)
$iTo | [optional] The page number at which to end publishing (default = keyword Default = end at the last page)
$bOpenAfterPublish | [optional] True displays the file in viewer after it is published (default = False)

## Return Value

Success: | the object of the exported 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 - $sFileName is empty 4 - Error exporting the object. @extended is set to the COM error code returned by the ExportAsFixedFormat method

## Related

_Excel_Print

## 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_Export Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oExcel, _Extras_PathFull("_Excel1.xls"), True)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example", "Error opening workbook '" & _Extras_PathFull("_Excel1.xls'.") & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

    ; Export cells A1:E10 of the active worksheet as PDF and display the file.
    Local $sOutput = @TempDir & "\_Excel1_1.pdf"
    _Excel_Export($oExcel, "A1:E10", $sOutput, Default, Default, Default, Default, Default, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example 1", "Error saving range to '" & $sOutput & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example 1", "Range successfully exported as '" & $sOutput & "'.")

### 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_Export Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oExcel, _Extras_PathFull("_Excel1.xls"), True)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example", "Error opening workbook '" & _Extras_PathFull("_Excel1.xls'.") & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

    ; Export the whole workbook as PDF.
    Local $sOutput = @TempDir & "\_Excel1_2.pdf"
    _Excel_Export($oExcel, $oWorkbook, $sOutput)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example 2", "Error saving the workbook to '" & $sOutput & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example 2", "The whole workbook was successfully exported as '" & $sOutput & "'.")