Export (0) Print
Expand All

Documents.Open Method

Office 2007
Opens the specified document and adds it to the Documents collection. Returns a Document object.


expression.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenConflictDocument, OpenAndRepair, DocumentDirection, NoEncodingDialog)

expression   Required. A variable that represents a Documents collection.


NameRequired/OptionalData TypeDescription
FileNameRequiredVariantThe name of the document (paths are accepted).
ConfirmConversionsOptionalVariantTrue to display the Convert File dialog box if the file isn't in Microsoft Word format.
ReadOnlyOptionalVariantTrue to open the document as read-only. This argument doesn't override the read-only recommended setting on a saved document. For example, if a document has been saved with read-only recommended turned on, setting the ReadOnly argument to False will not cause the file to be opened as read/write.
AddToRecentFilesOptionalVariantTrue to add the file name to the list of recently used files at the bottom of the File menu.
PasswordDocumentOptionalVariantThe password for opening the document.
PasswordTemplateOptionalVariantThe password for opening the template.
RevertOptionalVariantControls what happens if FileName 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.
WritePasswordDocumentOptionalVariantThe password for saving changes to the document.
WritePasswordTemplateOptionalVariantThe password for saving changes to the template.
FormatOptionalVariantThe file converter to be used to open the document. Can be one of the WdOpenFormat constants. The default value is wdOpenFormatAuto.
FormatRequiredVariantThe file converter to be used to open the document. Can be one of the following WdOpenFormat constants. To specify an external file format, apply the OpenFormat property to a FileConverter object to determine the value to use with this argument.
EncodingOptionalVariantThe document encoding (code page or character set) to be used by Microsoft Word when you view the saved document. Can be any valid MsoEncoding constant. For the list of valid MsoEncoding constants, see the Object Browser in the Visual Basic Editor. The default value is the system code page.
VisibleOptionalVariantTrue if the document is opened in a visible window. The default value is True.
OpenConflictDocumentOptionalVariantSpecifies whether to open the conflict file for a document with an offline conflict.
OpenAndRepairOptionalVariantTrue to repair the document to prevent document corruption.
DocumentDirectionOptionalWdDocumentDirectionIndicates the horizontal flow of text in a document. The default value is wdLeftToRight.
NoEncodingDialogOptionalVariantTrue to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.

Return Value


Avoid using hard-coded passwords in your applications. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code. For recommended best practices on how to do this, see Security Notes for Microsoft Office Solution Developers.


This example opens MyDoc.doc as a read-only document.

Visual Basic for Applications
Sub OpenDoc()
    Documents.Open FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True
End Sub

This example opens Test.wp using the WordPerfect 6.x file converter.

Visual Basic for Applications
Sub OpenDoc2()
    Dim fmt As Variant
    fmt = Application.FileConverters("WordPerfect6x").OpenFormat
    Documents.Open FileName:="C:\MyFiles\Test.wp", Format:=fmt
End Sub

Community Additions

© 2015 Microsoft