VBA & Macro Problems

How to Remove Green Highlighting from Specific Words in Word with VBA

Chanuka GeekiyanageChanuka Geekiyanage Oct 22, 2026 869 views

Question details

The user needs a VBA macro to remove green highlighting from specific matched words in a document.

How to Remove Green Highlighting from Specific Words in Word with VBA
Product
Word
Device & OS
not provided
Scenario
After running an initial macro that highlights selected words, unwanted green highlighting remains. The user wants to selectively remove the green highlights based on a specific searched word.
Observed behavior
Green highlighting persists on certain words. A targeted VBA script is required to prompt for a search term, validate the highlight color, and clear the highlighting only where conditions are met.
Before you start

Ensure that the Developer tab is enabled in your Ribbon so you can access the VBA Editor, and remember to save a backup of your document before executing new macros.

Solution 1Recommended

Use VBA to Specifically Remove Bright Green Highlighting

This macro searches for a specific word and removes its highlight only if the existing highlight color is bright green.

This method is ideal when your document contains multiple highlight colors and you strictly want to remove the bright green ones from a specific search term.

By leveraging the ActiveDocument.Range object and checking the HighlightColorIndex property, the script safely targets the exact formatting required.

1
Open the VBA Editor

Open your document and press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications window.

2
Insert a New Module

From the top menu, click on 'Insert' and select 'Module'. This will open a blank window where you can write your code.

3
Paste the VBA Code

Paste the following script into the module: Sub RemoveGreenHighlight() Dim oRng As Range Dim sText As String sText = InputBox("Enter the word to find") Set oRng = ActiveDocument.Range With oRng.Find .Highlight = True .Text = sText .MatchWholeWord = True Do While .Execute If oRng.HighlightColorIndex = wdBrightGreen Then oRng.HighlightColorIndex = wdNoHighlight End If Loop End With End Sub

4
Run the Macro

Press F5 or click the Run button. An InputBox will appear prompting you to enter the target word. Type the word and click OK. The macro will scan the document and clear the bright green highlights from the matching text.

Use VBA to Specifically Remove Bright Green Highlighting
Adjusting the Green Color Code: If your original highlight used standard green instead of bright green, you must change 'wdBrightGreen' to 'wdGreen' in the VBA code.

Automate Tasks with VBA Macros in WPS Writer

WPS Office provides excellent built-in support for VBA macros in its Writer application. You can write, edit, and run VBA scripts to manage highlights and automate repetitive formatting tasks effortlessly.

  1. 1. Open WPS Writer: Launch WPS Office and open your text document in the WPS Writer application.
  2. 2. Access the Developer Tools: Navigate to the 'Developer' tab on the top ribbon. If you do not see it, you can enable it from the software settings.
  3. 3. Open the VBA Editor: Click on the 'Macros' or 'Visual Basic' icon to open the integrated VBA editor.
  4. 4. Run Your Script: Insert a new module, paste your highlight-clearing VBA code, and press F5 to execute the automated task directly within WPS Office.
Fully compatible with Microsoft Word macro-enabled formats (.docm, .doc, .docx).Seamless support for Visual Basic for Applications (VBA) to execute complex scripts.Lightweight, fast, and completely free to download and use.Familiar ribbon interface makes transitioning and finding developer tools intuitive.
microsoft office alternative - wps office

Frequently Asked Questions

How do I change the macro to remove yellow highlighting instead?

In the VBA editor, locate the line 'If oRng.HighlightColorIndex = wdBrightGreen Then' and change 'wdBrightGreen' to 'wdYellow'. This ensures the macro explicitly targets yellow formatting for removal.

Can I remove highlights from multiple specific words at once?

Yes. Instead of using an InputBox for a single word, you can modify the VBA script to loop through an array of predetermined strings. The macro will then perform the find and replace action for each word in the list.

Why does the macro fail to find my highlighted text?

The macro may fail if the search term does not match exactly. The script uses '.MatchWholeWord = True' and '.MatchCase = True' to ensure accuracy. If your highlighted word contains trailing spaces, differing capitalization, or punctuation, the execution loop will skip it. Try turning off '.MatchCase' or verifying your input.