Export (0) Print
Expand All

Open Method


This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

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. An expression that returns a Documents object.

FileName  Required Variant. The name of the document (paths are accepted).

ConfirmConversions  Optional Variant. True to display the Convert File dialog box if the file isn't in Microsoft Word format.

ReadOnly  Optional Variant. True to open the document as read-only. Note 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.

AddToRecentFiles  Optional Variant. True to add the file name to the list of recently used files at the bottom of the File menu.

PasswordDocument  Optional Variant. The password for opening the document.

PasswordTemplate  Optional Variant. The password for opening the template.

Revert  Optional Variant. Controls 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.

WritePasswordDocument  Optional Variant. The password for saving changes to the document.

WritePasswordTemplate  Optional Variant. The password for saving changes to the template.

WdOpenFormat can be one of these WdOpenFormat constants.
wdOpenFormatAllWord
wdOpenFormatAuto The default value.
wdOpenFormatDocument
wdOpenFormatEncodedText
wdOpenFormatRTF
wdOpenFormatTemplate
wdOpenFormatText
wdOpenFormatUnicodeText
wdOpenFormatWebPages

To specify an external file format, apply the OpenFormat property to a FileConverter object to determine the value to use with this argument.

Encoding  Optional Variant. The 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.

Visible  Optional Variant. True if the document is opened in a visible window. The default value is True.

OpenConflictDocument  Optional Variant. Specifies whether to open the conflict file for a document with an offline conflict.

OpenAndRepair  Optional Variant. True to repair the document to prevent document corruption.

WdDocumentDirection can be one of these WdDocumentDirection constants.
wdLeftToRight default
wdRightToLeft

NoEncodingDialog  Optional Variant. True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.

Opens the specified object.

expression.Open

expression   Required. An expression that returns an OLEFormat object.

Opens the specified object. Returns a Document object representing the opened object.

expression.Open

expression   Required. An expression that returns one of the above objects.

Example

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

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.

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

This example opens each document in the RecentFiles collection.

Sub OpenRecentFiles()
    Dim rFile As RecentFile
    For Each rFile In RecentFiles
        rFile.Open
    Next rFile
End Sub

This example opens the most recent version of Report.doc.

Sub OpenVersion()
    Dim mydoc As Document
    Set mydoc = Documents.Open("C:\MyFiles\Report.doc")
    If mydoc.Versions.Count > 0 Then
        mydoc.Versions(mydoc.Versions.Count).Open
    Else
        MsgBox "There are no saved versions for this document."
    End If
End Sub
Show:
© 2015 Microsoft