Function Reference


_Word_Quit

Closes all documents, the Word application and removes the object reference to it

#include <Word.au3>
_Word_Quit ( $oAppl [, $iSaveChanges = $WdDoNotSaveChanges [, $iOriginalFormat = $WdWordDocument [, $bForceClose = False]]] )

Parameters

$oAppl Word object returned by a preceding call to _Word_Create()
$iSaveChanges [optional] Specifies if changed documents should be saved before closing.
Can be one of the WdSaveOptions enumeration (default = $WdDoNotSaveChanges)
$iOriginalFormat [optional] Specifies how Word saves documents whose original format was not Word document format.
Can be any of the WdOriginalFormat enumeration (default = $WdWordDocument)
$bForceClose [optional] If True the Word application is closed even when it was running at _Word_Create() time (default = False)

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - $oAppl is not an object
2 - Error returned by method Application.Quit. @extended is set to the COM error code

Remarks

If Word was not running when _Word_Create() was called then _Word_Quit() closes all documents of the specified
instance (even those opened manually by the user after _Word_Create() ) and the Word application.
If Word was running you have to set $bForceClose to True to do the same.

Related

_Word_Create

Example

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

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

; *****************************************************************************
; If Word was running when this script is started only the reference to the
; object will be removed.
; If Word was started by this example all documents and Word will be closed.
; *****************************************************************************
Local $iResult
If $bWordClose Then
    $iResult = MsgBox(BitOR($MB_OKCANCEL, $MB_SYSTEMMODAL), "Word UDF: _Word_Quit Example", _
            "If you click OK ALL unsaved changes in ALL open documents of this Word instance will be lost and the instance will be closed.")
Else
    $iResult = MsgBox(BitOR($MB_OKCANCEL, $MB_SYSTEMMODAL), "Word UDF: _Word_Quit Example", _
            "Word was already running when function _Word_Create was called. Hence only the reference to the object will be removed.")
EndIf
If $iResult = 2 Then Exit
_Word_Quit($oWord)
If @error Then MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_Quit Example", _
        "Error closing the Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)