View Single Post
 
Old 03-28-2023, 06:04 AM
syl3786 syl3786 is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Default Remove two highlight colors at the same time

Hi community,

Thank you experts for helping me to edit the VBA codes in the previous post (https://www.msofficeforums.com/word-...highlight.html)

I have encountered another issue. When I tried to remove two highlight colours at the same time, the same issue came out again. That is, two highlight colours connected together cannot be identified by the macro and be removed. (See attached file as demo)

Code:
Sub ClearTurquoise()

Call ClearPink

Dim oRngStory As Range
  For Each oRngStory In ActiveDocument.StoryRanges
    Do
      With oRngStory.Find
        .Highlight = True
        Do While .Execute
          If oRngStory.HighlightColorIndex = wdTurquoise Then
             oRngStory.HighlightColorIndex = wdNoHighlight
             oRngStory.Collapse 0
          End If
        Loop
      End With
      'Get next linked story (if any)
      Set oRngStory = oRngStory.NextStoryRange
    Loop Until oRngStory Is Nothing
  Next
lbl_exit:
  Exit Sub
End Sub

Sub ClearPink()
Dim oRngStory As Range
  For Each oRngStory In ActiveDocument.StoryRanges
    Do
      With oRngStory.Find
        .Highlight = True
        Do While .Execute
          If oRngStory.HighlightColorIndex = wdpink Then
             oRngStory.HighlightColorIndex = wdNoHighlight
             oRngStory.Collapse 0
          End If
        Loop
      End With
      'Get next linked story (if any)
      Set oRngStory = oRngStory.NextStoryRange
    Loop Until oRngStory Is Nothing
  Next
lbl_exit:
  Exit Sub
End Sub
Does anyone can help edit the code so that it can identify those texts with more than one highlight colors and remove them automatically by the macro?

Your help will be greatly appreciated!
Attached Files
File Type: docx test.docx (14.1 KB, 5 views)
Reply With Quote