VBA & Macro Problems

Use a Word VBA Macro to Find and Highlight Gender Terms

Emma BrownEmma Brown Nov 20, 2026 870 views

Question details

Find whole-word gender terms in a Word document, highlight them by category, and remove the highlights after review.

Find and Highlight Gender Terms with a Word VBA Macro
Product
Microsoft Word
Device & OS
not provided
Scenario
The user wants to review terms such as he, she, his, and her without treating different capitalizations as separate terms.
Observed behavior
Male and female terms are highlighted in different colors, with a separate macro available to clear the highlighting.
Before you start

Open the document in desktop Word and make sure you can access the VBA editor and the Macros dialog. Test the code in a copy first, and review Word's macro security settings before running code from another source.

Solution 1Recommended

Create macros to highlight and clear gender terms

Use case-insensitive, whole-word searches to color the terms in the document's main text and clear those colors when the review is complete.

The example uses turquoise for he and his, and pink for she and her. It searches the main document text, not headers, footers, or text boxes.

Both macros affect existing highlights on matching terms: the first replaces them, and the second removes them rather than restoring their previous colors.

1
Open a VBA module

In desktop Word, open the VBA editor from Developer > Visual Basic. Select the document's project, then choose Insert > Module.

2
Paste the macros

Paste the following code into the module: Sub HighlightGenderTerms() HighlightGenderTerm "he", wdTurquoise HighlightGenderTerm "his", wdTurquoise HighlightGenderTerm "she", wdPink HighlightGenderTerm "her", wdPink End Sub Sub ClearGenderTermHighlights() HighlightGenderTerm "he", wdAuto HighlightGenderTerm "his", wdAuto HighlightGenderTerm "she", wdAuto HighlightGenderTerm "her", wdAuto End Sub Private Sub HighlightGenderTerm(ByVal term As String, ByVal color As WdColorIndex) Dim searchRange As Range Dim documentEnd As Long Set searchRange = ActiveDocument.Content documentEnd = searchRange.End With searchRange.Find .ClearFormatting .Text = term .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Do While searchRange.Find.Execute searchRange.HighlightColorIndex = color If searchRange.End >= documentEnd Then Exit Do searchRange.SetRange Start:=searchRange.End, End:=documentEnd Loop End Sub

3
Save and run the review macro

Use File > Save As to save the document as a Word Macro-Enabled Document (.docm) if you want to retain the macros in it. Return to the document, open Developer > Macros, select HighlightGenderTerms, and choose Run.

4
Clear the term highlights

After reviewing the document, open Developer > Macros, select ClearGenderTermHighlights, and choose Run. This clears highlighting from the listed terms but leaves highlights on other text unchanged.

Create macros to highlight and clear gender terms
Add or change terms: To review another whole-word term, add a HighlightGenderTerm line for it to both macros, using the desired color in the first and wdAuto in the second.
Free Microsoft Office alternative

Review Word documents in WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Use WPS Writer's find and highlight tools for a manual review and move existing documents over with format compatibility. It does not fix Microsoft Word's VBA macro behavior.

Find and manually highlight terms during a document review.Open and edit Microsoft Word DOC and DOCX files.Work with familiar document-editing controls in a lightweight office suite.Move existing Word documents into WPS Writer without starting from scratch.
microsoft office alternative - wps office

Frequently Asked Questions

Will the macro find HE and She as well as lowercase terms?

Yes. The code sets MatchCase to False, so capitalization does not affect the search. MatchWholeWord is also enabled to avoid matching the terms inside longer words.

How do I change the highlight colors?

In the VBA editor, change the color argument in the HighlightGenderTerms procedure, such as wdTurquoise or wdPink, to another supported Word highlight color.

Will clearing the highlights restore colors that were there before?

No. ClearGenderTermHighlights sets the listed terms' highlighting to wdAuto. It does not remember or restore any earlier highlight colors on those terms.

Why are terms in headers or text boxes not highlighted?

The example searches ActiveDocument.Content, which covers the main document text. Headers, footers, and text boxes require additional code to search their separate story ranges.

Can I run this Word macro in EditScript?

The code uses Microsoft Word's VBA object model. Check EditScript or eScription documentation and support to determine whether your version provides a compatible VBA environment before trying to run it there.