You need to replace italic text in a Word document without affecting formatting of surrounding content. The Find and Replace dialog can search for italic formatting, but it cannot replace the text while keeping the formatting intact without a macro. This article explains how to create a Word macro that finds all italic text and replaces it with new text while preserving the italic style.
Key Takeaways: Macro to Replace Italic Text
- Alt+F11 (VBA Editor): Opens the editor where you paste the macro code.
- Selection.Find.Format = True: Enables the macro to search for text with italic formatting.
- .Font.Italic = True: Tells the Find object to locate only text formatted as italic.
- Selection.TypeText: Inserts the replacement text while keeping the italic style active.
- File > Options > Customize Ribbon > Developer: Enables the Developer tab needed to run macros.
What the Macro Does and What You Need Before Starting
Word’s built-in Find and Replace can locate italic text by using Format > Font > Italic in the Find dialog. However, when you replace the found text, Word removes the italic formatting unless you manually reapply it. A macro solves this by keeping the italic font style active during the replacement.
The macro uses VBA (Visual Basic for Applications) to loop through each instance of italic text in the document. For each occurrence, it selects the italic text, replaces it with new text you specify, and then reapplies the italic format. The result is that all original italic text becomes your new replacement text, still in italic.
Before you begin, you must enable the Developer tab in Word. Without it, you cannot access the VBA editor. Also, save your document before running any macro. Macros cannot be undone with Ctrl+Z after they run through multiple replacements.
Steps to Create and Run the Find and Replace Italic Macro
- Enable the Developer tab
Open Word. Go to File > Options > Customize Ribbon. In the right column under Main Tabs, check the box next to Developer. Click OK. The Developer tab now appears on the ribbon. - Open the VBA editor
Click the Developer tab. In the Code group, click Visual Basic. Alternatively, press Alt+F11 on your keyboard. - Insert a new module
In the VBA editor, go to Insert > Module. A blank code window appears. This is where you paste the macro code. - Paste the macro code
Copy the following code exactly and paste it into the module window:Sub ReplaceItalicText() Dim ReplaceWith As String ReplaceWith = InputBox("Enter the replacement text:", "Replace Italic Text") If ReplaceWith = "" Then Exit Sub Selection.HomeKey Unit:=wdStory With Selection.Find .ClearFormatting .Font.Italic = True .Text = "" .Format = True .Forward = True .Wrap = wdFindStop End With Do While Selection.Find.Execute Selection.TypeText Text:=ReplaceWith Selection.Font.Italic = True Loop End Sub - Run the macro
Close the VBA editor. On the Developer tab, click Macros. Select ReplaceItalicText from the list and click Run. A dialog box asks for the replacement text. Type your text and click OK. The macro scans the document and replaces every italic word or phrase with your text, keeping the italic format. - Save the macro for future use
To reuse the macro in other documents, save it in the Normal.dotm template. In the VBA editor, right-click Normal under Project Explorer and choose Export File. Save the .bas file. To import, right-click Normal and choose Import File, then select the .bas file.
Common Mistakes and Limitations When Using the Macro
The macro replaces text inside fields or headers
The macro searches the main body of the document. If italic text appears inside a text box, header, footer, or field code, the macro may skip it. To include headers and footers, you must modify the code to iterate through each StoryRange. For most users, the main body coverage is sufficient.
The replacement text does not appear in italic
If the macro runs but the new text loses italic formatting, the problem is usually that the Selection.Font.Italic = True line was not executed. Check that the code includes this line inside the loop. Also ensure that the document does not have conflicting character styles that override italic.
The macro stops after finding the first instance
This happens if the .Wrap = wdFindStop line is missing or set to wdFindContinue. The code shown above uses wdFindStop, which causes the loop to end when no more matches are found. If the macro stops early, verify that the Find object properties are set exactly as shown.
Undoing the macro changes
Word’s undo stack does not record macro actions. Before running the macro, save your document. If the result is incorrect, close the document without saving and reopen the saved version. Alternatively, keep a backup copy of the file.
Built-in Find and Replace vs Macro for Italic Text
| Item | Built-in Find and Replace | Macro (VBA) |
|---|---|---|
| Search for italic formatting | Yes, via Format > Font > Italic | Yes, via .Font.Italic = True |
| Replace text while keeping italic | No, italic is lost after replacement | Yes, reapplies italic automatically |
| Requires VBA knowledge | No | Yes, must paste and run code |
| Undoable | Yes, single Ctrl+Z | No, must rely on backup |
| Speed on large documents | Fast | Slower, processes each match individually |
| Works in headers and footers | Yes, if search scope includes them | No, unless code is extended |
If you only need to replace one or two italic phrases, use the built-in Find and Replace and manually reapply italic formatting. For bulk replacements across many documents, the macro saves time and ensures consistency.
If the Macro Does Not Find Any Italic Text
Italic formatting may be applied via a character style
The macro searches for direct italic formatting, not italic defined within a style. If your italic text uses a style named Emphasis or similar, the macro will not find it. To fix this, modify the Find object to search for the style instead. Replace the line .Font.Italic = True with .Style = "Emphasis" (or the actual style name).
The document contains no italic text
Run a quick check: press Ctrl+H, click inside the Find what box, click Format > Font > Italic, and then click Find In > Main Document. Word highlights all italic text. If none appear, there is no italic text to replace.
The macro is not signed or macros are disabled
Word blocks macros by default. On the Developer tab, click Macro Security. Select Enable all macros (not recommended for untrusted code) or add the document’s location to the Trusted Locations list. After changing the setting, close and reopen the document.
You can now create and run a Word macro that finds all italic text and replaces it with new content while preserving the italic format. Test the macro on a sample document before using it on critical files. For more control, explore the VBA object model to add features like case sensitivity or wildcard support.