Function Reference


_Word_DocClose

Closes the specified Word document

#include <Word.au3>
_Word_DocClose ( $oDoc [, $iSaveChanges = $WdDoNotSaveChanges [, $iOriginalFormat = $WdOriginalDocumentFormat]] )

Parameters

$oDoc Word document object
$iSaveChanges [optional] Specifies the save action for the document (default = $WdDoNotSaveChanges).
Can be one of the WdSaveOptions constants:
    $WdDoNotSaveChanges, $WdPromptToSaveChanges or $WdSaveChanges
$iOriginalFormat [optional] Specifies the save format for the document.
Can be one of the WdOriginalFormat constants:
    $WdOriginalDocumentFormat, $WdPromptUser or $WdWordDocument (default = $WdOriginalDocumentFormat)

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - $oDoc is not an object
2 - Error retuned when closing the specified document. @extended is set to the COM error code

Related

_Word_DocAdd, _Word_DocAttach, _Word_DocOpen

Example

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

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

; Close a Word coument
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocClose Example", "Press 'OK' to close document '.\Extras\Test.doc'.")
_Word_DocClose($oDoc)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocClose Example", _
                "Error closing document '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocClose Example", "The document has been closed successfully.")