Macro Error when Closing Document

by Allen Wyatt
(last updated February 21, 2008)

Patricia Malyon is experiencing a situation where she is getting errors whenever she closes a document. Specifically, the error says "Compile Error in Hidden Module: Main." This error is caused by a macro that is somehow failing to run, as Word expects it to, every time a document closes.

If this error occurs with every document being closed, there is a good chance that the offending macro is in the template. Another clue is that the "Main" reference indicates that the macro is probably from an older, pre-Word 97 version of Word. (Prior to Word 97 the macro language used was WordBasic, and it used Main as the name of the primary entry point for a macro.) If you've upgraded recently to a newer version of Word, then the macro that used to work fine under your older version of Word may now have problems in the newer version.

The only way to fix such a problem is to examine the add-ins and macros associated with your documents and templates. Tracking down the problem can be frustrating, particularly if you are unfamiliar with macros and the VBA Editor, but it is the only way to really fix the problem. Chances are good that the offending macro is part of (or referenced in) a FileClose or AutoClose macro.

One good online source of information for problems such as this is at the Word MVP site. Take a look at the following Web page, particularly section four. It includes information and guidance that may be helpful:

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (188) applies to Microsoft Word , , , , and .

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...


Maximizing Your Editing Space

If you have a large, high-resolution monitor, you may not be starved for screen space. Some people, however, aren't as ...

Discover More

Compound List Formatting

Word can help you do quite a bit of complex formatting to your lists, both bulleted and numbered. Using the steps outlined in ...

Discover More

Pasting a Graphic to Multiple Worksheets

Do you need to add a logo or other graphic to a bunch of worksheets? Here are a couple of short macros that can make quick ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!


Attaching Macros to Documents

When you distribute documents to other people, you may want those documents to have associated macros that the reader can ...

Discover More

Hiding Macros

Don?t want a particular macro to be visible in the Macros dialog box? Once you understand the criteria that Word uses when ...

Discover More

Changing a Macro Description

Part of documenting macros is to provide a good, succinct description of what they do. Changing the description of an ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)