VBA: Change highlight color (RGB not wbColor) with keyboard shorcut (MS Word 2013)

I have this module in VBA assigned to a keyboard shorcut to change the color of highlight:

Sub RotateHighlightwbColor()
  Select Case Selection.Range.HighlightColorIndex
    Case wdYellow
        Selection.Range.HighlightColorIndex = wdGray25
    Case wdGray25
        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

But instead of wbColor I want to use RGB color(more choices of color).

I could find a way to do it but it uses Shading instead of Highlights.

Sub RotateHighlightRGB()
Select Case Selection.Font.Shading.BackgroundPatternColor

    Case RGB(255, 255, 255)
        Selection.Font.Shading.BackgroundPatternColor = RGB(1, 255, 1)
    Case RGB(1, 255, 1)
        Selection.Font.Shading.BackgroundPatternColor = RGB(0, 0, 0)
    Case RGB(0, 0, 0)
        Selection.Font.Shading.BackgroundPatternColor = RGB(255, 255, 255)
    Case Else
        Selection.Font.Shading.BackgroundPatternColor = RGB(255, 255, 255)
    End Select
End Sub

Is there a way to use RGB color with Selection.Range.HighlightColorIndex instead of using Shading?


I believe the answer to "Can we change the highlight color" is No. The HighlightColorIndex must refer to an "Applies to" list of constants. The set for the WdColorIndex constants (MSDN Word 2003) is …

wdAuto wdBlack wdBlue wdBrightGreen wdByAuthor wdDarkBlue wdDarkRed wdDarkYellow wdGray25 wdGray50 wdGreen wdNoHighlight wdPink wdRed wdTeal wdTurquoise wdViolet wdWhite wdYellow

This list is similar to an emuneration without the numbers, it is a set or collection that must be used with this particular limited property. There is no Highlight object that I have found referenced.

In the shading example given, the .shading "property" actually returns a shading object which can access the full RGB Color Model as your code above demonstrates and is referenced many places including https://msdn.microsoft.com/en-us/library/dd355244.aspx

The Office 2003 remarks for WdColorIndex explain the wdByAuthor entry in the list above.

"If the InsertedTextColor property is set to wdByAuthor, Microsoft Word automatically assigns a unique color to each of the first eight authors who revise a document."