Fix a Word VBA Macro That Applies a Style to the Entire Document
Question details
The user needs a Word macro to apply a style only to text in a specific source font.

- Product
- Microsoft Word VBA
- Device & OS
- not provided
- Scenario
- A recorded macro uses Find and Replace to apply a style to text with a particular font.
- Observed behavior
- The macro changes all text because its recorded Find criteria do not specify the source font.
Identify the exact source font name and the name of the style you want to apply. Check whether the style is a character or paragraph style, because a paragraph style can affect an entire paragraph.
Add the Source Font to the Word VBA Find Criteria
Edit the recorded macro so Find matches the intended font before applying the replacement style.
In Word, open the VBA editor with Alt+F11, then locate the recorded macro in its module.
Inside the With Selection.Find block, add .Font.Name = "Times New Roman" after Selection.Find.ClearFormatting. Replace Times New Roman with the exact source font name.
Confirm that the macro sets .Format = True inside the Find block and assigns the intended style with Selection.Find.Replacement.Style, such as ActiveDocument.Styles("LD"). Replace LD with the name of your existing style.
Return to Word, run the macro from the Macros dialog, and check that the style was applied to the intended text.

Edit and Format Word Documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for editing and styling documents. Its Microsoft Word format compatibility makes it easy to move documents between applications. It does not repair a Microsoft Word VBA macro.

Frequently Asked Questions
Why does the recorded macro format all text?
The macro recorder omitted the source font from the Find criteria. With an empty search text and no font criterion, the replacement can match more content than intended.
Where should I add the font name in the macro?
In the VBA editor, add .Font.Name = "Your Font Name" inside the With Selection.Find block, after Selection.Find.ClearFormatting.
Why did a whole paragraph change when only some text matched?
The replacement may be a paragraph style, which applies to the paragraph containing the match. Check the style type in Word and use a suitable character style if you only want to format matching text.
Can WPS Office fix my Word VBA macro?
No. Edit the recorded macro in Microsoft Word's VBA editor to fix its Find criteria. WPS Writer is an alternative for editing and formatting compatible Word documents.




