#1
|
|||
|
|||
VBA Code to remove specific highlight
Hi Community,
This is a macro for removing specific highlight in Word Documents. When you place the cursor at the highlighted text (e.g., it highlighted wdYellow), then ran the macro, it can remove all wdYellow highlights in that word document. However, I found a bug in the "Removeonehighlight" macro. When there are words highlighted with two colors and connected each other like 123456, the macro cannot remove the highlight color, neither red or yellow one. (see the attached word file) The code are as follows: Code:
Sub Removeonehighlight() Dim HLColor As WdColorIndex Dim rg As Range HLColor = Selection.Range.HighlightColorIndex If HLColor <> wdNoHighlight Then Set rg = ActiveDocument.Range With rg.Find .Highlight = HLColor .Wrap = wdFindStop While .Execute If rg.HighlightColorIndex = HLColor Then rg.HighlightColorIndex = wdNoHighlight End If rg.Collapse wdCollapseEnd Wend End With Else MsgBox "Please place you cursor on the highlight color you want to remove." End If End Sub Your help would be greatly appreciated! |
#2
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find .Highlight = True While .Execute Select Case oRng.HighlightColorIndex Case Is = 9999999 oRng.HighlightColorIndex = wdAuto End Select oRng.Collapse wdCollapseEnd Wend End With lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Quote:
|
#4
|
|||
|
|||
First, while a common mistake, I am not Gmayor.
If you want to get rid of red highlighting in a mix of red and some other color: Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oRng As Range Dim oChr As Range Set oRng = ActiveDocument.Range With oRng.Find .Highlight = True While .Execute Select Case oRng.HighlightColorIndex Case Is = 9999999 For Each oChr In oRng.Characters If oChr.HighlightColorIndex = wdRed Then oChr.HighlightColorIndex = wdAuto End If Next Case Is = wdRed oRng.HighlightColorIndex = wdAuto End Select oRng.Collapse wdCollapseEnd Wend End With lbl_Exit: Exit Sub End Sub Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oRng As Range Dim oChr As Range Set oRng = ActiveDocument.Range With oRng.Find .Text = "*" .MatchWildcards = True .Highlight = True While .Execute Select Case oRng.HighlightColorIndex Case Is = wdRed oRng.HighlightColorIndex = wdAuto End Select oRng.Collapse wdCollapseEnd Wend End With lbl_Exit: Exit Sub End Sub |
#5
|
|||
|
|||
Quote:
|
Tags |
highlight, macro, word vba |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA Highlight numbers only after or before specific words help | Shelley Lou | Word VBA | 12 | 08-09-2022 03:02 AM |
Remove highlight with specific color | rekent | Word VBA | 2 | 08-01-2020 10:59 AM |
How to highlight lines containing specific words | SixStringSW | Word VBA | 4 | 06-03-2018 03:57 PM |
VBA to highlight specific values in the spreadsheet | daiwuliz | Excel | 6 | 05-23-2018 10:30 AM |
Highlight the current cell without using code | parshla | Excel | 0 | 09-08-2016 08:10 PM |