3

I have a 100+ pages Word document full of highlighted setences that I have to correct. Once i am done I have to remove the highlighting.

That's easy with the Ctrl+Alt+H shorcut if all the highlightings are of the same color. (Ctrl + Space dremoves the styles but doesn't remove the highlightings. )

But mines are of several different colors so each time I have to select the color in the ribbon which makes the shortcut useless.

Is there a way to set up a shorcut (or a simplify procedure) that will be able to remove highlighting without having to set it in the ribbon?

enter image description here

EDIT1

This macro is working (the RGB is at the end of the loop, and no "case is based on it")

  Select Case Selection.Range.Font.ColorIndex
    Case wdRed
        Selection.Range.Font.ColorIndex = wdPink
    Case wdPink
        Selection.Range.Font.ColorIndex = wdYellow
    Case wdYellow
        Selection.Range.Font.ColorIndex = wdBlue
     Case wdBlue
        Selection.Range.Font.TextColor.RGB = RGB(0, 176, 240)
    Case wdAuto
        Selection.Range.Font.ColorIndex = wdRed
    Case Else
        Selection.Range.Font.ColorIndex = wdAuto
    End Select

End Sub

But not this one (Case RGB(0,176,240) isn't recognized)

  Select Case Selection.Range.Font.ColorIndex
    Case wdRed
        Selection.Range.Font.ColorIndex = wdPink
    Case wdPink
        Selection.Range.Font.ColorIndex = wdYellow
    Case wdYellow
        Selection.Range.Font.ColorIndex = wdBlue
     Case wdBlue
        Selection.Range.Font.TextColor.RGB = RGB(0, 176, 240)
     Case RGB(0, 176, 240)
        Selection.Range.Font.TextColor.RGB = RGB(256, 176, 240)
    Case wdAuto
        Selection.Range.Font.ColorIndex = wdRed
    Case Else
        Selection.Range.Font.ColorIndex = wdAuto
    End Select

End Sub

So I have tried something like that but still without success (nothing is recognized)

  Select Case Selection.Range.Font.TextColor.RGB
    Case RGB(255, 0, 0)
        Selection.Range.Font.TextColor.RGB = RGB(1, 255, 1)
    Case RGB(1, 255, 1)
        Selection.Range.Font.TextColor.RGB = RGB(0, 0, 0)
    Case RGB(0, 0, 0)
        Selection.Range.Font.TextColor.RGB = RGB(255, 0, 0)
    Case Else
        Selection.Range.Font.ColorIndex = RGB(0, 0, 0)
    End Select

End Sub
4

Unfortunately, I don't know of an existing shortcut to do this.

Fortunately, I was sufficiently frustrated by there not being a shortcut to do this, that I wrote a macro to do it for me:

Sub RotateHighlight()
'
' Rotates highlighting of selected text between:
'   None, yellow, green, blue, red, pink, none, yellow, green, ...
'
' If the selected text is highlighted with anything other than these colors,
'  the highlight is removed.  Also, if the selection includes text whose
'  highlighting is not uniform, all highlighting is removed from the selection.
'

    Select Case Selection.Range.HighlightColorIndex
    Case wdYellow
        Selection.Range.HighlightColorIndex = wdBrightGreen
    Case wdBrightGreen
        Selection.Range.HighlightColorIndex = wdTurquoise
    Case wdTurquoise
        Selection.Range.HighlightColorIndex = wdRed
    Case wdRed
        Selection.Range.HighlightColorIndex = wdPink
    Case wdNoHighlight
        Selection.Range.HighlightColorIndex = wdYellow
    Case Else
        Selection.Range.HighlightColorIndex = wdNoHighlight
    End Select

End Sub

In order to have this macro available as a keyboard shortcut any time you're working in Word, open the VBA editor (Open any Word doc and press Alt-F11) and create a code module in the Normal template:

VBA snip

Copy/paste the above code into the newly created Module and save with Ctrl-S. Close the VBA Editor.

In Word, click the tiny down-arrow-triangle with the bar over it that's to the right of the Quick Access Toolbar and select 'More Commands':

Word snip

In the resulting dialog box, select 'Customize Ribbon' from the left-hand list, and then click 'Customize' next to 'Keyboard shortcuts' at the bottom:

Word snip

The following dialog should appear:

Word snip

Under 'Categories', scroll all the way to the bottom and select 'Macros'. Under 'Macros', select 'RotateHighlight'. (Unless you already are a VBA programmer, RotateHighlight will probably be the only item under 'Macros' here.) Click into 'Press new shortcut key', and then press your desired shortcut key combination. I personally like to have it set to Ctrl-Alt-Shift-H. Be sure it says '[unassigned]' next to 'Currently assigned to:', then click 'Assign' at the bottom. 'Close' when done, and test it out!

For your purposes, select the text you want to remove highlighting from, plus some additional un-highlighted text around it, and then run the macro. That should clear all highlighting in the selection.

  • You're a genius. This macro is so great and it doing even more than what I was expecting! Thanks for the detailed tuto, I am not used to do macro and with your help it was so easy! – MagTun Dec 27 '14 at 13:27
  • <tips hat> My pleasure! I use it constantly at work, in situations that sound almost exactly like yours. Huge timesaver. – hBy2Py Dec 27 '14 at 13:59
  • You gave me that idea to create a macro for the color of text. I have tried to replace HighlightColorIndex by ColorIndex but it didn't work. If you have a macro for that under the elbow, let me know I will ask another question about that, so you can get more points! – MagTun Dec 27 '14 at 14:59
  • You were close: replacing .HighlightColorIndex with .Font.ColorIndex, not just .ColorIndex, should work. You can also set the font color to cycle through arbitrary RGB colors of your choice by setting the values of .Font.TextColor.RGB. For example, bright red is: Selection.Range.Font.TextColor.RGB = RGB(255,0,0) – hBy2Py Dec 27 '14 at 15:42
  • 1
    I think the easiest way will be a two-level If structure. As the outer test, use If Selection.Range.Font.TextColor.RGB >=0. This will be True when .RGB is set to an actual RGB value, instead of some mysterious internal VBA Enum code, and can then be tested directly in an inner If ... .RGB = RGB(rrr,ggg,bbb) test. Whenever the outer If is False, you'll have to figure out what .ColorIndex applies and test for that. Unfortunately, this probably means some limitations on the text colors you can actually use. – hBy2Py Jan 5 '15 at 14:17
0

This one is working

  Select Case Selection.Range.Font.TextColor.RGB
    Case RGB(0, 0, 0) 'black
        Selection.Range.Font.TextColor.RGB = RGB(255, 0, 0) 'red
    Case RGB(255, 0, 0) 'red
        Selection.Range.Font.TextColor.RGB = RGB(255, 102, 178) 'pink
    Case RGB(255, 102, 178)
        Selection.Range.Font.TextColor.RGB = RGB(51, 153, 255) 'blue ciel
    Case RGB(51, 153, 255)
        Selection.Range.Font.TextColor.RGB = RGB(178, 102, 255) 'violet
    Case RGB(178, 102, 255)
        Selection.Range.Font.TextColor.RGB = RGB(102, 204, 0) 'Green
    Case RGB(102, 204, 0)
        Selection.Range.Font.TextColor.RGB = RGB(0, 0, 0) 'black
    Case Else
        Selection.Range.Font.TextColor.RGB = RGB(0, 0, 0) 'black
    End Select

End Sub
0

Can you select the entire document?  If you can, do that and then click on “Highlight” → “No Color”.

            “Highlight” → “No Color”

Or, if you prefer the keyboard, use Alt H I N.

0

I used the following code in a macro to remove highlights in any colour and assigned it an Alt+N shortcut key:

Selection.Range.HighlightColorIndex = wdNoHighlight
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
  • "End Sub" should actually be the last line in the macro - not sure why it ended up outside the gray box.. – user843651 Dec 3 '17 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.