How to: Save Documents
Some code examples in this topic use the this or Me keyword or the
There are several ways to save and close Microsoft Office Word 2003 documents, depending on what results you desire. Ifand are applied to a object, only that document is affected. If applied to the collection, all open documents are affected.
The Save method saves changes to a specified Document.
To save the document associated with the project
To save the active document
Call themethod 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.
Themethod 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
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.
Compiling the Code
This code example requires the following:
To save a document by name, a document named
NewDocument.docmust exist in a directory named
Teston the C: drive.
To save a document to a new name, a directory named
Testmust exist on the C: drive.