This documentation is archived and is not being maintained.

How to: Save Documents


Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

There are several ways to save and close Microsoft Office Word 2003 documents, depending on what results you desire. If Save and Close are applied to a Document object, only that document is affected. If applied to the Documents collection, all open documents are affected.

The Save method saves changes to a specified Document.

To save the document associated with the project

  • Call the Save method of ThisDocument.


To save the active document

  • Call the Save method for the active document.


If you are not sure if the document you want to save is the active document, you can refer to it by its name.

To save a document specified by name

  • Use the document name as an argument to the Documents collection.

    object fileName = @"C:\Test\NewDocument.doc"; 
    this.Application.Documents.get_Item(ref fileName).Save(); 


The SaveAs method allows you to save a document under another file name. It requires that you specify the new file name, but other arguments are optional.


If you show the SaveAs dialog box inside of the DocumentBeforeSave event handler of ThisDocument and set the Cancel parameter to false, the application might quit unexpectedly. If you set the Cancel parameter to true, an error message appears indicating that Autosave has been disabled.

To save a document using SaveAs

  • Call the SaveAs method on ThisDocument, using a fully qualified path and file name. If a file by that name already exists in that folder, it is silently overwritten.


    The SaveAs method generates an exception if a target directory does not exist or if there are other problems saving a file. It is a good practice to use a try/catch block around the SaveAs method or inside a calling method.

    object fileName = @"C:\Test\NewDocument.doc"; 
    this.SaveAs(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);

Compiling the Code

This code example requires the following:

  • To save a document by name, a document named NewDocument.doc must exist in a directory named Test on the C: drive.

  • To save a document to a new name, a directory named Test must exist on the C: drive.

See Also