VBA & Macro Problems

How to Fix Word VBA Macros Not Applying Text Formatting

Partner EditorPartner Editor Oct 12, 2026 872 views

Question details

The user needs to know why a recorded Word VBA macro successfully inserts text but fails to apply formatting like font color, bold, or italics, and how to correct the VBA code.

How to Fix Word VBA Macros Not Applying Text Formatting
Product
Microsoft Word
Device & OS
not provided
Scenario
Running a recorded VBA macro to automatically insert and format specific text in a document.
Observed behavior
The macro inserts the text correctly but omits the formatting because the text selection is collapsed at the end of the inserted string before the formatting command executes.
Before you start

Before modifying your macro code, ensure that the Developer tab is enabled in your software ribbon so you can easily access the Visual Basic editor.

Solution 1Recommended

Rewrite the Macro to Format Inserted Text Directly

Modify the recorded VBA code to assign text directly to the Selection object and immediately apply the formatting.

Recorded macros often fail to apply formatting because the 'Selection.TypeText' command leaves the cursor at the end of the text. This means nothing is actually highlighted when the subsequent font formatting commands execute.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) window.

2
Locate your macro code

In the Project Explorer pane on the left, find and open the module (e.g., Module1) that contains your recorded macro.

3
Modify text insertion

Find the line that says 'Selection.TypeText Text:="Your Text"' and change it to 'Selection.Text = "Your Text"'.

4
Apply formatting

Add your formatting commands directly below this line, such as 'Selection.Font.Color = wdColorRed' or 'Selection.Font.Bold = True'.

5
Save and test

Save your modified code, close the VBA editor, and run the macro again to verify the formatting is applied properly.

Rewrite the Macro to Format Inserted Text Directly
Tip: Using Selection.Text instead of Selection.TypeText automatically selects the inserted string, ensuring that any formatting commands applied immediately after will affect that specific text.
Free Microsoft Office alternative

Try WPS Office for Seamless Document Management

If you want a lightweight, user-friendly word processor that perfectly handles document formatting, Styles, and layouts without the complexity of constant troubleshooting, WPS Writer is an excellent choice. It serves as a highly compatible, free alternative to Microsoft Word.

  1. 1. Download the installer: Visit the official WPS Office website and click the free download button.
  2. 2. Install WPS Office: Run the downloaded installer file and follow the simple on-screen instructions to set up the software.
  3. 3. Open your Word documents: Launch WPS Writer and open your existing .docx files to seamlessly continue your work with full format retention.
Fully compatible with Microsoft Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) formats.Intuitive user interface for easily managing text formatting, Styles, and document layouts without writing code.Lightweight installation and incredibly fast startup times.Free to use for everyday document creation and editing.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the macro recorder miss text formatting steps?

The macro recorder strictly captures actions in sequence. When you insert text using the standard typing method (which translates to Selection.TypeText), the cursor is left at the end of the word. Since no text is highlighted when you subsequently click the formatting buttons, the recorded macro applies formatting to an empty selection.

What is the difference between Selection and Range in VBA?

The Selection object represents the current active area or cursor position in the document, which shifts constantly as actions are performed. A Range object defines a fixed, specific portion of the document independent of where the user's cursor is, making Range-based macros much more reliable and faster.

Can I use VBA macros in WPS Office?

Yes, WPS Office supports VBA macros. However, full VBA support is typically included in the Professional or Premium versions of WPS Office, which allow you to record, run, and edit macros much like you would in Microsoft Office.