VBA & Macro Problems

Fix a Word VBA Macro That Applies a Style to the Entire Document

Algirdas JasaitisAlgirdas Jasaitis Nov 18, 2026 868 views

Question details

The user needs a Word macro to apply a style only to text in a specific source font.

Fix a Word VBA Macro That Applies a Style to the Entire Document
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the macro

In Word, open the VBA editor with Alt+F11, then locate the recorded macro in its module.

2
Add the font criterion

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.

3
Check the replacement settings

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.

4
Run and check the macro

Return to Word, run the macro from the Macros dialog, and check that the style was applied to the intended text.

Add the Source Font to the Word VBA Find Criteria
Check the style type: A paragraph style can change the formatting of an entire paragraph even when only part of it matches the font. Use a suitable character style if only matching text should receive the style.
Free Microsoft Office alternative

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.

Apply styles and format text in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesUse a familiar interface for a smoother transition from OfficeWork with a free, lightweight office suite
microsoft office alternative - wps office

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.