WD: WordBasic Macro to Replace Font Formatting

Last reviewed: November 17, 1997
Article ID: Q88854
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

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 : kbmacroexample macword winword winword2 word6 word7 word95 kbmacro
Version : WINDOWS: 1.0, 1.1, 2.0, 6.0, 7.0; MACINTOSH: 6.0, 6.0.1
Platform : MACINTOSH WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.