You are visitor number ????? since 14 October 2004.
Go to Howard Kaikow's home page

Copyright © 1999 by Howard Kaikow. All rights reserved.
Date: 10 September 1999
From: Howard Kaikow <kaikow@standards.com>
Subject: Macro recording is unreliable and not a good way to learn VBA


It is often stated that one way to learn how to use Word VBA is to record macros and examine the resultant code. Unfortunately, one cannot trust the code produced by recording macros. For example:

  1. Word performs certain operations when you issue commands through the user interface that are not reflected in the code recorded for those operations.

    One example is using the Edit | Find menu to search for text that is in a, say, header, when the cursor is in the body of the document. Word performs some operations for you which are not included in the recorded code. If you run the recorded macro, and the cursor is not in the appropriate header, the search will fail to find the text in the header.

  2. Sometimes, Word will generate code that is just plain incorrect, even though the operations you request through the user interface will work correctly. My current favorite example may be easily reproduced.

    It is not uncommon for a template in the Office Startup directory to include AutoText. To reproduce an example of this problem, try the following:

  3. The macro recorder generates very poor code, for example:

    Such code will execute much more slowly than most any reasonable manual coding.

  4. Etc.