logo
search
VBA & Macro Problems

How to Automatically Format Outlook Email Text Using Word VBA

Ayan MasoodAyan Masood Oct 15, 2026 869 views

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.

How to Automatically Format Outlook Email Text Using Word VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Outlook VBA Editor

Press Alt + F11 while in Outlook to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

Right-click on Project1 in the Project Explorer, select Insert, and then click Module to create a blank script area.

3
Set the Email Format to HTML

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.

4
Access the Word Document Object

Set an object variable to access the underlying Word editor using the syntax 'Set objDoc = ActiveInspector.WordEditor'.

5
Configure the Find and Replace Action

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.

6
Apply Font Color and Execute

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.

Add Word Object Library Reference: To use Word-specific constants such as wdReplaceAll in Outlook VBA, you must go to Tools > References in the VBA Editor and check the box for Microsoft Word Object Library. Alternatively, you can use the numeric value '2' in place of wdReplaceAll.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and download the free installer for your operating system.
  2. 2. Install the Software: Run the setup file and follow the quick installation prompts to set up WPS Office on your computer.
  3. 3. Open Your Documents: Launch WPS Office and instantly open your existing Word, Excel, and PowerPoint files without formatting loss.
Highly compatible with Microsoft Word documents (.docx) and complex formatting.Free and lightweight, consuming minimal system resources.Built-in support for JS macros to automate repetitive tasks across documents.Familiar user interface requires no learning curve for easy migration.
microsoft office alternative - wps office

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.