WD2000: Font Is Not Changed When You Run Recorded Macro (269870)
The information in this article applies to:
This article was previously published under Q269870 SYMPTOMS
When you run a recorded macro that is designed to find text that is formatted in one font and change that text to a different font, the text is not changed to the new font.
CAUSE
Only formatting that is directly applied to text is recorded in a macro. The formatting that exists before the macro recorder is started is not coded into the macro, either. Therefore, you must manually add the specific names of the fonts used in a Find/Replace procedure, to the macro code in the Visual Basic Editor.
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For more information about how to use the sample code in this article, click
the article number below to view the article in the Microsoft Knowledge
Base:
212536
OFF2000: How to Run Sample Code from Knowledge Base Articles
Modify your recorded macro to include the font name that you want to find by using the Font property, and the font name that you want to replace it with by using the Replacement property. Your modified recorded macro should look similar to the following example:
Sub TestMacro()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
' Add the following Font Property and specify the name of the
' font you want to find.
.Font.Name = "Courier New"
.Replacement.Text = ""
' Add the following Replacement Property and specify the name of
' the font you want to replace with.
.Replacement.Font.Name = "Times New Roman"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCESFor additional information about programming in a Visual Basic for Applications macro, click the article number below
to view the article in the Microsoft Knowledge Base:
212623 WD2000: Macro Programming Resources
226118 OFF2000: Programming Resources for Visual Basic for Applications
Modification Type: | Major | Last Reviewed: | 6/17/2005 |
---|
Keywords: | kbbug kbdtacode kbmacro kbmacroexample kbnofix KB269870 |
---|
|