It’s occasionally convenient to close a document without saving your changes. For example, you might create a new document to use as a scratch pad or to test out a new feature. Similarly, you might open an existing document, make some temporary changes, and then close the document without saving those changes. In each case, when you choose Office, Close, Word asks if you want to save the document. This not only slows you down by requiring an extra step that you don’t need, but there’s also the real danger that you might click Yes by accident.
To work around these problems, I use a macro that automatically closes a document withÂout saving any changes and without prompting to save changes. Listing 1 shows the macro.
Listing 1 A Macro That Closes a Document Without Saving Changes
As you can see, this is a simple procedure that runs only the ActiveDocument object’s Close method with the SaveChanges argument set to the constant value wdDoNotSaveChanges.
A more involved example is shown in Listing 2.
Listing 2 A Macro That Closes a Document Without Saving Changes and Then Reopens the Document


This macro first uses various properties of the ActiveWindow object to save the document’s current window state, position, and dimensions. Then the code saves the document’s full path name (as given by the FullName property), and the document is closed without saving changes. The Open method reopens the document, and then the window is restored to its former state, position, and dimensions.
CAUTION
Be sure to move the CloseAndReopen macro to a document other than the one that you’ll be closing and reopening. (For example, you could store it in the Normal template.) Otherwise, when the document is closed, the code module is closed along with it, so the document can’t reopen.
Technorati Tags: closing document without saving, word 2007
Popularity: 3% [?]








Recent Comments