WD: WordBasic Macro to Replace Font Formatting

ID: Q88854

The information in this article applies to:

SUMMARY

The following Microsoft Word macro examples can be used to change all characters formatted in one font to another font. For example, you could change all characters that originally occur in Arial to a font such as Times New Roman.

MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

CAUTION: Save your file before you run these macros because changes made by running the following macros cannot be reversed by clicking Undo on the Edit menu. If you don't like the changes that occur when you run a macro, close your document without saving changes in order to "undo" the macro operation.

NOTE: The font names in the following macros must be spelled as they appear in the dialog box that appears when you choose Font from the Format menu. These macros do not affect the point size of the font.

Word 6.0, 6.0a, 6.0c, 7.0, 7.0a

The following macro changes all Arial-formatted characters in a document to Courier New.

   Sub Main
      StartOfDocument
      EditFindFont .Font = "Arial"
      EditReplaceFont .Font = "Courier New"
      EditReplace .Find = "", .Replace = "", .Format = 1,
      .ReplaceAll, .Wrap = 1
   End Sub

Word 2.x

The following macro changes all Arial-formatted characters in a document to Courier New.

   Sub Main
      StartOfDocument
      EditFindChar .Font = "Arial"
      EditReplaceChar .Font = "Courier New"
      EditReplace .Find = "", .Replace = "", .Format = 1, .ReplaceAll
   End Sub

NOTE: The above macro does not prompt you before it changes the font. In order to be prompted to replace each occurrence of the font, remove the .ReplaceAll argument from the final EditReplace line of the macro.

Word for Windows 1.x

The following macro changes all Helvetica-formatted characters in a document to Courier:

   Sub MAIN
      StartOfDocument
      EditSearchChar .Font = "Helvetica"
      EditReplaceChar .Font = "Courier"
      EditReplace .Confirm = 0, .Format = 1
   End Sub

The above macro will not prompt you when it finds an occurrence of the Helvetica font. Because Confirm is set to 0, all occurrences will be changed at once (throughout the entire document). In order to be prompted for each change, set the Confirm option to 1 in the above macro example.

REFERENCES

"Using WordBasic," by Microsoft and WexTech Systems, pages 181, 187

Additional query words: search character

Keywords          : kbmacro kbmacroexample winword macword word6 winword2 word7 word95 
Version           : WINDOWS: 1.0, 1.1, 2.0, 6.0, 7.0; MACINTOSH: 6.0, 6.0.1
Platform          : MACINTOSH WINDOWS
Issue type        : kbinfo

Last Reviewed: November 19, 1997