# Function Reference

# _Word_DocOpen

Opens a Word document

#include <Word.au3>
_Word_DocOpen ( $oAppl, $sFilePath [, $bConfirmConversions = False [, $iFormat = $WdOpenFormatAuto [, $bReadOnly = False [, $bRevert = False [, $bAddToRecentFiles = False [, $sOpenPassword = "" [, $sWritePassword = ""]]]]]]] )

## Parameters

$oAppl | Word object returned by a preceding call to _Word_Create()
$sFilePath | The name or full path of the document to open
$bConfirmConversions | [optional] True displays the Convert File dialog if the file isn't in Word format (default = False)
$iFormat | [optional] Specifies the format to use when opening the document. Can be any of the WdOpenFormat enumeration (default = $WdOpenFormatAuto = the existing format)
$bReadOnly | [optional] True to open the document as read-only (default = False). Note: This argument doesn't override the read-only recommended setting on a saved document.
$bRevert | [optional] Controls what happens if $sFilePath is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document (default = False)
$bAddToRecentFiles | [optional] True adds the file name to the list of recently used files at the bottom of the File menu (default = False)
$sOpenPassword | [optional] The password for opening the document
$sWritePassword | [optional] The password for saving changes to the document

## Return Value

Success: | a variable pointing to the document object. @extended is set to 1 if $bReadOnly = False but read-write access could not be granted. Please see the Remarks section for details.
Failure: | sets the @error flag to non-zero.
@error: | 1 - $oAppl is not an object 2 - The specified document does not exist 3 - Error occurred when opening specified document. @extended is set to the COM error code

## Remarks

When you set $bReadOnly = False but the document can't be opened read-write @extended is set to 1.
The document was opened read-only because it has already been opened by another user/task or the file is set to read-only by the filesystem.
If you modify the document you need to use _Word_DocSaveAs() to save it to another location or with another name.

## Related

_Word_DocClose, _Word_DocSave, _Word_DocSaveAs

## Example

    #include "Extras\HelpFileInternals.au3"

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

    ; Create application object
    Local $oWord = _Word_Create()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocOpen Example", _
            "Error creating the Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

    ; Open a document read-only
    Local $sDocument = _Extras_PathFull("Test.doc")
    _Word_DocOpen($oWord, $sDocument, Default, Default, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocOpen Example 1", "Error opening '.\Extras\Test.doc'." & _
            @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocOpen Example 1", "Document '" & $sDocument & "' has been opened successfully.")