Delen via


How to: Programmatically open existing documents

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

The Open method opens the existing Microsoft Office Word document specified by a fully qualified path and file name. This method returns a Document that represents the opened document.

Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Word. For more information, see Features available by Office application and project type.

To open a document

  • Call the Open method of the Documents collection and supply a path to the document.

    Me.Application.Documents.Open("C:\Test\NewDocument.docx")
    
    this.Application.Documents.Open(@"C:\Test\NewDocument.docx");
    

To open a document as read-only

  • Call the Open method, supply a path to the document, and set the ReadOnly argument to True in the method call.

    Me.Application.Documents.Open(FileName:="C:\Test\NewDocument.docx", ReadOnly:=True)
    
    this.Application.Documents.Open(@"C:\Test\NewDocument.docx", ReadOnly:true);
    

Compile the code

This code example requires the following:

  • A document named NewDocument.doc must exist in a directory named Test on drive C.

See also