|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Close Documents
Some code examples in this topic use the this or Me keyword or the
You can use themethod to close Microsoft Office Word 2003 documents and specify whether you want to save the document when you close it.
The document can be one of two types:
Thehost item is created at design time. For more information on host items, see .
Native Word object.
Using Host Items
The following code assumes you have written the code in the ThisDocument class.
To close the active document without saving changes
Call the Close method to specify the document associated with the project.
This example includes the wdDoNotSaveChanges argument of the Close method to close without saving changes or prompting the user.
Using Word Objects
The following code assumes you have programmatically added a Microsoft.Office.Interop.Word.Document to your project and named it NewDocument.
To close a document and save changes without prompting
Specify the document name as an argument to thecollection.
This example includes the wdSaveChanges argument of the method to save without prompting.