Cleaning Up
The well-behaved macro cleans up after itself. In the course of carrying out its various tasks, a macro may open and close documents, change the settings of various options, and make other modifications before it is finished. Some of these changes may not be desirable to the user after the macro is done. For example, a macro designed to work on selected text may create a bookmark to mark an area of the document. The macro needs this bookmark, but the user doesn't; the macro should remove the bookmark when it's no longer needed.
Here's a checklist of possible cleanup tasks for your macro:
- Close any documents the macro opened that the user doesn't need.
- Save a document with changes that should be saved.
- Close a document without saving it if the macro made changes that should not be saved. If the document should be open but unchanged when the macro ends, close it without saving changes, and then reopen it.
- Restore the settings of any options the macro may have changed for its own purposes. For example, if hidden text was not displayed when the macro began, it should not be displayed when the macro ends (unless that is part of the purpose of the macro).
- Delete any temporary bookmarks created by the macro.
- Restore the original selection or return the insertion point to the appropriate location.
- Restore the original size of the document window.
- Re-enable auto macros if the macro disabled them. Auto macros remain disabled for the entire Word session if the macro does not re-enable them before it ends.
- Return to the original folder.