In this article, we are delighted to show you 2 useful methods to replace the highlight color in your Word document.
Sometimes you may highlight different contents with different colors. But unlike font color, you cannot utilize the “Find and Replace” to find texts in a specific highlight color and replace it with another one.
Therefore, we are going to need some workarounds. Following are 2 ways available for different cases.
Method 1: Replace All Highlight Colors with the Same One
The highlight color associated to “Find and Replace” dialog box is the current one selected in the Highlight icon.
- First of all, under “Home” tab and in “Font” group, click on the drop-down button on “Text Highlight Color” command. Pick a color to which you want change all highlight colors. For example, we choose “Bright Green” here.
- Then press “Ctrl+ H” to trigger the “Find and Replace” dialog box.
- Put cursor inside “Find what” text box.
- Click “More” to bring out more options and click “Format”.
- And choose “Highlight”.
- Next put cursor inside “Replace with” box and repeat step 4 and 5.
- Lastly, click “Replace All”.
Now you have replaced all highlight colors with the bright green.
Method 2: Replace a Specific Highlight Color with Another
To accomplish this task, a macro is required.
- First and foremost, press “Alt+ F11” to open VBA editor.
- Next click “Normal” project on the left column.
- Then click “Insert” tab on the menu bar.
- And choose “Module” on that drop-down menu.
- Open the new module by double click.
- Now paste following codes:
Sub ReplaceOneHighlightColorToAnother() Dim strFindColor As String Dim strReplaceColor As String Dim objDoc As Document Dim objRange As Range Application.ScreenUpdating = False Set objDoc = ActiveDocument strFindColor = InputBox("Specify a color (enter the value):", "Specify Highlight Color") strReplaceColor = InputBox("Specify a new color (enter the value):", "New Highlight Color") With Selection .HomeKey Unit:=wdStory With Selection.Find .Highlight = True Do While .Execute If Selection.Range.HighlightColorIndex = strFindColor Then Set objRange = Selection.Range objRange.HighlightColorIndex = strReplaceColor Selection.Collapse wdCollapseEnd End If Loop End With End With Application.ScreenUpdating = True End Sub
- Next click “Run” button or hit “F5”.
- Then in the “Specify Highlight Color” box, enter a value represent the color to be replaced. To get the corresponding value of a specific color, you can visit this link: https://docs.microsoft.com/en-us/office/vba/api/Word.WdColorIndex
- For instance, if we want to replace the yellow color with bright green, we enter “7” in “Specify Highlight Color” box and click “OK”.
- Then in “New Highlight Color” box, enter a value of the new color and click “OK”.
Here is the possible outcome of replacing yellow with bright green.
Avoid Data Loss Disaster
Word is such a great helper in our daily work. Therefore, it’s not hard to imagine the catastrophe it can bring when it collapses. To avoid losing critical data, you can get hold of a Word fix tool in advance. With such a utility at hand, you should not need to worry about the data loss.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupt xlsx and pdf repair software products. For more information visit www.datanumen.com
I think the macro only works if there is an unhighlighted gap between colours. If you have two different colours of highlight touching each other the macro finds one example of highlighting and determines that its “colour” is 999999 or something weird like that, the code for mixed. The only way round this is to then go through the mixed highlighting character by character to determine where the colour change happens, and then identify the range as two separate colour ranges, to which the macro can apply separately. It is possible but much clunkier and slower.
test
I copied your VBA code and ran it. No error but it didn’t appear to do anything. I tried several variations of highlight colors such as pink (5), yellow (7), and bright green (4). Perhaps there was a VBA update with Office 365 version, which caused this change. The find and replace worked fine.