Function Reference


_Word_DocExport

Exports the document or a range as PDF or XPS

#include <Word.au3>
_Word_DocExport ( $oDoc, $sFileName [, $iFormat = $WdExportFormatPDF [, $iRange = $WdExportAllDocument [, $iFrom = Default [, $iTo = Default [, $bOpenAfterExport = False [, $bIncludeProperties = True [, $iCreateBookmarks = Default [, $bUseISO19005 = False]]]]]]]] )

Parameters

$oDoc Word document object to be exported
$sFileName Path/name of the exported file
$iFormat [optional] Format to use for the export. Can be any of the WdExportFormat enumeration
(default = $WdExportFormatPDF)
$iRange [optional] Specifies what to export. Can be any of the WdExportRange enumeration
(default = $WdExportAllDocument)
$iFrom [optional] The page number at which to start publishing (default = start at the beginning)
$iTo [optional] The page number at which to end publishing (default = end at the last page)
$bOpenAfterExport [optional] True displays the file in a viewer after it is published (default = False)
$bIncludeProperties [optional] True indicates that document properties should be included (default = True)
$iCreateBookmarks [optional] Specifies whether to export bookmarks and the type of bookmarks to export.
Can be any of the WdExportCreateBookmarks enumeration (default)
$bUseISO19005 [optional] Specifies whether the export should be created as PDF/A (self-contained PDF) (default = False)

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - $oDoc is not an object
2 - $sFileName is empty
3 - Error returned when exporting the object. @extended is set to the COM error code

Related

_Word_DocPrint

Example

Example 1

#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 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)

; *****************************************************************************
; Export the complete document with default values
; *****************************************************************************
Local $sFileName = @TempDir & "\Test1.pdf"
_Word_DocExport($oDoc, $sFileName)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocExport Example", _
        "Error exporting the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
ShellExecute($sFileName)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocExport Example", _
        "The whole document has successfully been exported to: " & $sFileName)

Example 2

#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 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)

; *****************************************************************************
; Export a range as PDF/A and display the exported file
; *****************************************************************************
; Set the range to lines 2 and 3
Local $oRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 1, $wdParagraph, 2)
Local $sFileName = @TempDir & "\Test2.pdf"
_Word_DocExport($oRange, $sFileName, Default, $wdExportFromTo, Default, Default, True, Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocExport Example", "Error exporting the document." & _
        @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocExport Example", _
        "The specified range has successfully been exported to: " & $sFileName)

Example 3

#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 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)

; *****************************************************************************
; Export the current page
; *****************************************************************************
Local $sFileName = @TempDir & "\Test3.pdf"
_Word_DocExport($oDoc, $sFileName, Default, $wdExportCurrentPage)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocExport Example", _
        "Error exporting the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocExport Example", _
        "The current page has successfully been exported to: " & $sFileName)
ShellExecuteWait($sFileName)