How to Remove Green Highlighting from Specific Words in Word with VBA
Question details
The user needs a VBA macro to remove green highlighting from specific matched words in a document.

- 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.
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.
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.
Open your document and press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications window.
From the top menu, click on 'Insert' and select 'Module'. This will open a blank window where you can write your 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
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 Remove All Highlighting from a Specific Word
Use this alternative macro if you simply want to clear all highlighting from a searched word, regardless of the highlight color.
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. Open WPS Writer: Launch WPS Office and open your text document in the WPS Writer application.
- 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. Open the VBA Editor: Click on the 'Macros' or 'Visual Basic' icon to open the integrated VBA editor.
- 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.

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.




