Microsoft Visual Studio Tools for the Microsoft Office system (version 3.0)
How to: Open Existing Documents

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Word 2003

  • Word 2007

For more information, see Features Available by Application and Project Type.

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

To open a document

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

    Visual Basic
    Me.Application.Documents.Open("C:\Test\NewDocument.doc")
    
    C#
    object fileName = @"C:\Test\NewDocument.doc"; 
    
    this.Application.Documents.Open(ref fileName,
        ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing);
    

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.

    Visual Basic
    Me.Application.Documents.Open(FileName:="C:\Test\NewDocument.doc", ReadOnly:=True)
    
    C#
    object readOnly = true;
    object fileName = @"C:\Test\NewDocument.doc";
    
    this.Application.Documents.Open(ref fileName,
        ref missing, ref readOnly, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing);
    
Compiling 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

Tasks

Concepts

Tags :


Page view tracker