Microsoft KB Archive/66132

Word: Creating a Dynamic Search and Edit Macro

PSS ID Number: Q66132 Article last modified on 11-02-1994

5.00 5.50 6.00

MS-DOS

= SUMMARY =

It is often necessary to create a macro to perform repetitive searching and editing functions. For example, you could use a macro to search for a word and then format the word for bold and underline.

If a search and edit macro is document specific, it is very efficient and convenient to create a dynamic macro in which the subject of the search and edit can be changed easily.

Such a dynamic macro involves creating three macros: a main macro for the search loop, a dynamic search macro, and a dynamic edit macro.

The steps to create the macro in Word version 5.50, 6.00 are as follows:

rsearch <> redit rsearch <>

The steps to create the macro in Word version 5.50 are as follows:


 * 1) Enter the above macro in a new window. Highlight the macro and choose Macro Edit. Enter “main” for the macro name and choose Define.
 * 2) Open the document you want to edit.
 * 3) Move the cursor to the top of the document. Choose Macro Record and enter “search” as the macro name.
 * 4) Perform the procedure to search for the text or formatting you want to edit (do NOT edit at this point).
 * 5) Choose Macro Stop Recorder or press CTRL+F3.
 * 6) Choose Record Macro and enter “edit” as the macro name.
 * 7) Perform the desired editing or formatting on the search text (make sure to leave the cursor to the right of the edited area to ensure the accuracy of the next search).
 * 8) Choose Macro Stop Recorder or press CTRL+F3.

The main macro in Word version 5.00 should look like the following:

isearch <> iedit isearch <>

Enter the above macro in a new window. Highlight the macro and choose Copy. Enter the name of the macro (for example, “main”). The search and edit macros can be recorded in any document.

The following example explains how to create the dynamic search macro:


 * 1) Open the document you want to edit.
 * 2) Move the cursor to the top of the document. Press SHIFT+F3 to turn on the Record Macro function.
 * 3) Perform the procedure to search for the text or formatting that you want to edit (do NOT edit at this point).
 * 4) Press SHIFT+F3 to stop the recording and enter “search” for the macro name.
 * 5) Press SHIFT+F3 again to turn on the Record Macro feature.
 * 6) Perform the desired editing or formatting on the search text (make sure to leave the cursor to the right of the edited area to ensure the accuracy of the next search).
 * 7) Press SHIFT+F3 to stop the recording and enter “edit” for the macro name.

The “main” macro can now be run to perform the editing for the rest of the document. Steps 2-8 can be repeated for other procedures.

KBCategory: kbother kbmacro KBSubcategory: Additional reference words: replace ============================================================================= Copyright Microsoft Corporation 1994.