How to: Programmatically Save Visio Documents

 

There are several ways to save Microsoft Office Visio documents:

  • Save changes in an existing document.

  • Save a new document, or save a document with a new name.

  • Save a document with specified arguments.

For more information, see the VBA reference documentation for the Microsoft.Office.Interop.Visio.Document.Save method, Microsoft.Office.Interop.Visio.Document.SaveAs method, and Microsoft.Office.Interop.Visio.Document.SaveAsEx method.

To save a document

  • Call the Microsoft.Office.Interop.Visio.Document.Save method of the Microsoft.Office.Tools.Visio.Document class of a document that has been previously saved.

    To use this code example, run it from the ThisAddIn class in your project.

    System_CAPS_noteNote

    The Microsoft.Office.Interop.Visio.Document.Save method throws an exception if a new Visio document has not yet been saved.

    No code example is currently available or this language may not be supported.

Use the Microsoft.Office.Interop.Visio.Document.SaveAs method to save a new document, or a document that has a new name. This method requires that you specify the new file name.

To save the active Visio document with a new name

  • Call the Microsoft.Office.Interop.Visio.Document.SaveAs method of the Microsoft.Office.Tools.Visio.Document that you want to save, by using a fully qualified path including a file name. If a file by that name already exists in that folder, it is silently overwritten.

    To use this code example, run it from the ThisAddIn class in your project.

    No code example is currently available or this language may not be supported.

Use the Microsoft.Office.Interop.Visio.Document.SaveAsEx method to save a document with a new name, and specify any applicable arguments to apply to the document.

To save document with a new name and specified arguments

  • Call the Microsoft.Office.Interop.Visio.Document.SaveAsEx method of the Microsoft.Office.Tools.Visio.Document that you want to save, by using a fully qualified path including a file name. If a file by that name already exists in that folder, an exception is thrown.

    The following code example saves the active document with a new name, marks the document as read-only, and shows the document in the Most Recently Used list of documents. To use this code example, run it from the ThisAddIn class in your project.

    No code example is currently available or this language may not be supported.

Compiling the Code

This code example requires the following:

  • To save a document that has a new name, a directory named Test must be located in the My Documents folder (for Windows XP and earlier) or the Documents folder (for Windows Vista).

Show: