Office Settings & Configuration

How to Highlight Long Words in Word While Excluding Specific Terms

Nimra MalikNimra Malik Sep 28, 2026 869 views

Question details

The user wants to automatically highlight words that are eight letters or longer in a document, but exclude or differently color specific exception words using a VBA macro.

Highlight Long Words in Word While Excluding Specific Terms
Product
Microsoft Word
Device & OS
not provided
Scenario
Reviewing or formatting a document where long words need to be visually identified for editing purposes, while ignoring specific frequently used long terms.
Observed behavior
The user needs a VBA macro that uses wildcard search to find words of 8+ characters and applies conditional highlight colors based on an exception list string.
Before you start

Ensure the Developer tab is enabled in your Word ribbon to access the Visual Basic editor, and save your document as a Macro-Enabled Document (.docm) to preserve your script.

Solution 1Recommended

Use a VBA Macro to Conditionally Highlight Long Words

Run a custom VBA script to automatically scan the document, find words with 8 or more letters, and apply yellow highlighting, while applying red highlighting to specific exception words.

This macro uses Word's wildcard search capability (<[A-Za-z]{8,}>) to locate words that are 8 or more characters long. It then checks if the found word exists in a predefined 'Exceptions' string to apply the appropriate color.

1
Open the Visual Basic Editor

Press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the top menu, click on 'Insert' and select 'Module' to create a blank script window for your macro.

3
Paste and Customize the VBA Code

Copy and paste the following code into the module window: Sub Highlight8Plus() Dim Exceptions Exceptions = "|document|graphics|" Selection.HomeKey Unit:=wdStory With Selection.Find .ClearFormatting .Text = "<[A-Za-z]{8,}>" .MatchWildcards = True Do While .Execute If InStr(Exceptions, "|" & Selection.Text & "|") = 0 Then Selection.Range.HighlightColorIndex = wdYellow Else Selection.Range.HighlightColorIndex = wdRed End If Loop End With End Sub

4
Modify the Exceptions List

Change the words inside the Exceptions = "|document|graphics|" string to fit your needs. Keep the vertical bars (|) at the beginning, end, and between each word.

5
Run the Macro

Close the VBA editor and return to your document. Press Alt + F8 to open the Macros dialog, select Highlight8Plus, and click 'Run' to apply the highlights.

Use a VBA Macro to Conditionally Highlight Long Words
Case Sensitivity: The string comparison is case-sensitive by default. Ensure you include lowercase and uppercase variations in your exception list if needed, such as |document|Document|.
Advanced Text Formatting

Highlight Text Using Wildcards in WPS Writer

WPS Office Writer fully supports advanced Find and Replace functions using wildcards, allowing you to easily locate and highlight words of specific lengths without needing complex VBA code.

  1. 1. Open Find and Replace: Open your document in WPS Writer and press Ctrl + H to open the Find and Replace dialog box.
  2. 2. Enable Wildcards: Click on the 'Options' or 'More' button to expand the search settings, then check the 'Use wildcards' box.
  3. 3. Set the Search Criteria: In the 'Find what' box, type <[a-zA-Z]{8,}> to find all words containing 8 or more characters.
  4. 4. Apply Highlight Formatting: Click inside the 'Replace with' box (leave it empty textually). Then click 'Format' > 'Highlight' to set your desired background color for the text.
  5. 5. Execute the Highlighting: Click 'Replace All' to instantly scan the document and highlight all long words.
Free to download and use for daily document editingFully compatible with Microsoft Word document formats (.docx, .docm)Advanced wildcard search capabilities for rapid text formattingFamiliar ribbon interface for seamless migration without a learning curve
QA img-9

Frequently Asked Questions

Can I change the highlight colors used in the VBA macro?

Yes, you can modify the highlight colors by changing the constants wdYellow and wdRed in the VBA code to other Word color index constants, such as wdGreen, wdBlue, or wdTurquoise.

How do I make the exception list ignore case differences?

To make the comparison case-insensitive, you can modify the VBA code to use the LCase function. Change the condition line to: If InStr(LCase(Exceptions), "|" & LCase(Selection.Text) & "|") = 0 Then. Make sure your exceptions string contains only lowercase words.

Why isn't the macro finding words with exactly 8 letters?

Ensure your wildcard string is accurately typed as <[A-Za-z]{8,}>. The {8,} specifies exactly 8 or more characters. Also, verify that 'MatchWildcards = True' is correctly set in the macro.

How do I remove the highlights after reviewing the document?

To remove all highlights, select the entire document by pressing Ctrl + A, go to the Home tab, click the arrow next to the Text Highlight Color tool, and select 'No Color'.