1
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
?
Don't use colorindex, just use color. Also see this
– Raystafarian – 2015-02-19T17:14:04.910I have tried
Select Case Selection.Range.HighlightColor
and thenSelection.Range.HighlightColor = RGB(255, 255, 0)
(for instance), but VBA gives me an error: Compile error method or data member not found. I have tried withSelect Case Selection.Range.Interior.Color
(as suggested on your link, but it seems it's only working with excel not with word) – MagTun – 2015-02-21T08:40:57.173