How to Fix Word VBA Macros Not Applying Text Formatting
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.

- 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 modifying your macro code, ensure that the Developer tab is enabled in your software ribbon so you can easily access the Visual Basic editor.
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.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) window.
In the Project Explorer pane on the left, find and open the module (e.g., Module1) that contains your recorded macro.
Find the line that says 'Selection.TypeText Text:="Your Text"' and change it to 'Selection.Text = "Your Text"'.
Add your formatting commands directly below this line, such as 'Selection.Font.Color = wdColorRed' or 'Selection.Font.Bold = True'.
Save your modified code, close the VBA editor, and run the macro again to verify the formatting is applied properly.

Use a Range Object for Reliable Automation
Rewrite the macro using Range objects instead of the Selection object for cleaner and more robust VBA code.
Use Word Styles Instead of Direct Formatting
Apply a predefined Style via your macro or keyboard shortcut to ensure consistent formatting without writing complex VBA code.
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. Download the installer: Visit the official WPS Office website and click the free download button.
- 2. Install WPS Office: Run the downloaded installer file and follow the simple on-screen instructions to set up the software.
- 3. Open your Word documents: Launch WPS Writer and open your existing .docx files to seamlessly continue your work with full format retention.

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.




