Edit

Share via


Programmatically open Visio documents

There are two methods for opening existing Microsoft Office Visio documents: Open and OpenEx. The OpenEx method is identical to the Open method, except that it provides arguments in which the caller can specify how the document opens.

For details about the object model, see the VBA reference documentation for the Microsoft.Office.Interop.Visio.Documents.Open method and Microsoft.Office.Interop.Visio.Documents.OpenEx method.

Open a Visio document

To open a Visio document

  • Call the Microsoft.Office.Interop.Visio.Documents.Open method and supply the fully qualified path of the Visio document.

    string docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + @"\test\MyDrawing.vsd";
    this.Application.Documents.Open(docPath);
    

Open a Visio document with specified arguments

To open a Visio document as read-only and docked

  • Call the Microsoft.Office.Interop.Visio.Documents.OpenEx method, supply the fully qualified path of the Visio document, and include the arguments you want to use—in this case, Docked and Read-only.

    string docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + @"\test\MyDrawing.vsd";
    this.Application.Documents.OpenEx(docPath,
        ((short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked +
         (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenRO));
    

Compile the code

This code example requires the following:

  • A Visio document named myDrawing.vsd must be located in a directory named Test in the My Documents folder (for Windows XP and earlier) or the Documents folder (for Windows Vista).