Returns a collection object containing all documents or an object for a single document
#include <Word.au3>
_Word_DocGet ( $oAppl [, $vIndex = -1] )
$oAppl | Word object returned by a preceding call to _Word_Create() |
$vIndex | [optional] Specifies what to return: -1 - Returns a collection of all documents (default) 0 - Returns the active document n - The index number of the document to return (1 based) x - The name of the document to return |
Success: | a variable pointing to the collection of documents or a single document object. @extended is set to the total number of documents |
Failure: | 0 and sets the @error flag to non-zero. |
@error: | 1 - $oAppl is not an object 2 - $vIndex is invalid (< -1 or > Documents.Count) 3 - Specified document could not be found or error occurred. @extended is set to the COM error code 4 - Error returned when accessing the Documents collection. @extended is set to the COM error code |
#include <MsgBoxConstants.au3>
#include <Word.au3>
; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocGet Example", _
"Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open \Extras\test.doc read-only
_Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocGet Example", "Error opening '.\Extras\Test.doc'." & @CRLF & _
"@error = " & @error & ", @extended = " & @extended)
; Open \Extras\test2.doc read-only
_Word_DocOpen($oWord, @ScriptDir & "\Extras\Test2.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocGet Example", "Error opening '.\Extras\Test2.doc'." & @CRLF & _
"@error = " & @error & ", @extended = " & @extended)
; Get the first document in the collection, write name and total # of documents
; to the console.
Local $oDoc = _Word_DocGet($oWord, 1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocGet Example", _
"Error accessing collection of documents." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocGet Example", "First document in the document collection has been selected." & _
@CRLF & "Name is: " & $oDoc.Name & @CRLF & "Total number of documents in the collection: " & @extended)