Microsoft KB Archive/88854

{|
 * width="100%"|

WD: WordBasic Macro to Replace Font Formatting

 * }

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, versions 7.0, 7.0a
 * Microsoft 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 can 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 &quot;as is&quot; 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 &quot;undo&quot; 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 = &quot;Arial&quot; EditReplaceFont .Font = &quot;Courier New&quot; EditReplace .Find = &quot;&quot;, .Replace = &quot;&quot;, .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 = &quot;Arial&quot; EditReplaceChar .Font = &quot;Courier New&quot; EditReplace .Find = &quot;&quot;, .Replace = &quot;&quot;, .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 = &quot;Helvetica&quot; EditReplaceChar .Font = &quot;Courier&quot; 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.