Export (0) Print
Expand All

How to: Programmatically Create New Visio Documents

When you create a new Microsoft Office Visio drawing document, you add it to the Microsoft.Office.Interop.Visio.Documents collection of open Visio documents. Consequently, the Microsoft.Office.Interop.Visio.Documents.Add method creates a new Visio drawing document. For more information, see the VBA reference documentation for the Microsoft.Office.Interop.Visio.Documents.Add method.

To create a new document

  • Use the Microsoft.Office.Interop.Visio.Documents.Add method to create a new blank document that is not based on a template.

    this.Application.Documents.Add("");
    

The Microsoft.Office.Interop.Visio.Documents.Add method can create a new document that is a copy of an existing Visio document. You must supply the file name and fully qualified path of the diagram.

To create a new document that is copied from an existing document

  • Call the Microsoft.Office.Interop.Visio.Documents.Add method and specify the path of the Visio diagram.

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

The Microsoft.Office.Interop.Visio.Documents.Add method can create a new stencil that is a copy of an existing Visio stencil. You must supply the file name and fully qualified path of the stencil.

To create a new stencil that is copied from an existing stencil

  • Call the Microsoft.Office.Interop.Visio.Documents.Add method and specify the path of the stencil.

    string docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + @"\test\MyStencil.vss";
    this.Application.Documents.Add(docPath);
    

The Microsoft.Office.Interop.Visio.Documents.Add method can create a new document (a .vsd file) that is based on an existing Visio template (a .vst file). This method copies the stencils, styles, and settings that are part of the template workspace. You must supply the file name and fully qualified path of the template.

To create a new document that is based on an existing template

  • Call the Microsoft.Office.Interop.Visio.Documents.Add method and specify the path of the template.

    string docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + @"\test\MyTemplate.vst";
    this.Application.Documents.Add(docPath);
    

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).

  • A Visio document named myStencil.vss 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).

  • A Visio document named myTemplate.vst 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).

Show:
© 2014 Microsoft