How to Automatically Format Outlook Email Text Using Word VBA
Question details
The user needs to automate the formatting of specific text patterns, such as A.M. or P.M. times, within an email body before sending it.

- Product
- Microsoft Outlook
- Device & OS
- not provided
- Scenario
- Finding specific time formats in an active email draft and changing their font color using VBA automation.
- Observed behavior
- The user wants to manipulate the underlying Word document editor inside Outlook to apply rich text formatting automatically via macros.
Ensure that the Developer tab is enabled in your Outlook ribbon and that you have basic familiarity with writing and executing macros in the VBA editor.
Use Inspector.WordEditor to Run Wildcard Searches
Leverage Outlook's integration with Word to access the email body as a Word document, allowing you to use advanced wildcard searches to find and format time strings.
Because Outlook uses Microsoft Word as its native email editor, you can access the Word object model directly from Outlook VBA. By referencing the Inspector.WordEditor property, you gain access to Word's powerful Find and Replace capabilities, including wildcard pattern matching, to format text natively within your active email draft.
Press Alt + F11 while in Outlook to open the Microsoft Visual Basic for Applications window.
Right-click on Project1 in the Project Explorer, select Insert, and then click Module to create a blank script area.
In your macro, reference the active inspector (or selected message) and set the email's BodyFormat property to olFormatHTML so that it supports font color modifications.
Set an object variable to access the underlying Word editor using the syntax 'Set objDoc = ActiveInspector.WordEditor'.
Create a Range object from the document and configure its Find property to use wildcard text. Use a pattern like '([0-9]{1,2}:[0-9]{2} [APM][.][M])' to locate the times.
Set the Replacement.Font.Color property to your desired color (e.g., red) and run the ReplaceAll command to instantly update all matching time instances in the email.
Need a Powerful Office Suite? Try WPS Office
While advanced Outlook-Word VBA integration is specific to Microsoft Office, WPS Office offers a highly compatible, lightweight, and free alternative for your daily document, spreadsheet, and presentation tasks. It features robust document formatting and automation capabilities.
- 1. Download the Installer: Visit the official WPS Office website and download the free installer for your operating system.
- 2. Install the Software: Run the setup file and follow the quick installation prompts to set up WPS Office on your computer.
- 3. Open Your Documents: Launch WPS Office and instantly open your existing Word, Excel, and PowerPoint files without formatting loss.

Frequently Asked Questions
Can I run Word VBA macros directly in Outlook?
You cannot run native Word macros straight from the Outlook interface. However, you can write an Outlook macro that utilizes the Word Object Model via the Inspector.WordEditor property to achieve the exact same functionality inside an email.
Why do I get a 'variable not defined' error when using wdReplaceAll?
The constant wdReplaceAll is specific to the Word Object Library. If you are writing this in Outlook VBA, you must either add a reference to the Microsoft Word Object Library or use the number 2 instead of the constant name.
Does this macro work if my email is in plain text?
No. Plain text format does not support rich text elements like font colors or styling. You must ensure the email body format is set to HTML (olFormatHTML) or Rich Text before running the formatting macro.




