Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2023, 06:04 AM
syl3786 syl3786 is offline Remove two highlight colors at the same time Windows 10 Remove two highlight colors at the same time Office 2019
Advanced Beginner
Remove two highlight colors at the same time
 
Join Date: Jan 2023
Posts: 78
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, 3 views)
Reply With Quote
  #2  
Old 03-28-2023, 04:12 PM
Guessed's Avatar
Guessed Guessed is offline Remove two highlight colors at the same time Windows 10 Remove two highlight colors at the same time Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,974
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can use Select Case to act on multiple options at the same time. For example if you want to treat turquoise, pink AND mixed in the same way...
Code:
Sub ClearHilites()
  Dim oRngStory As Range
  For Each oRngStory In ActiveDocument.StoryRanges
    With oRngStory.Find
      .Highlight = True
      Do While .Execute
        Select Case oRngStory.HighlightColorIndex
          Case wdTurquoise, wdPink, 9999999
           oRngStory.HighlightColorIndex = wdNoHighlight
           oRngStory.Collapse 0
        End Select
      Loop
    End With
  Next
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-28-2023, 06:23 PM
syl3786 syl3786 is offline Remove two highlight colors at the same time Windows 10 Remove two highlight colors at the same time Office 2019
Advanced Beginner
Remove two highlight colors at the same time
 
Join Date: Jan 2023
Posts: 78
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
You can use Select Case to act on multiple options at the same time. For example if you want to treat turquoise, pink AND mixed in the same way...
Code:
Sub ClearHilites()
  Dim oRngStory As Range
  For Each oRngStory In ActiveDocument.StoryRanges
    With oRngStory.Find
      .Highlight = True
      Do While .Execute
        Select Case oRngStory.HighlightColorIndex
          Case wdTurquoise, wdPink, 9999999
           oRngStory.HighlightColorIndex = wdNoHighlight
           oRngStory.Collapse 0
        End Select
      Loop
    End With
  Next
End Sub
You expanded my horizons! Thank you so much for your help! It runs well!
Reply With Quote
Reply

Tags
highlight, vba, word macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove two highlight colors at the same time Highlight colors have changed to eliminate yellow QQQ Word 15 10-17-2022 11:40 AM
How to change colors to time values Ashikido Excel 6 02-01-2021 11:37 AM
Text/highlight colors in selection boxes changed kathleen Word 0 01-10-2018 07:45 PM
Need to put two highlight buttons on toolbar in different colors davidmrt Word 6 12-11-2011 05:54 AM
Remove two highlight colors at the same time Highlight one line at a time billy589 PowerPoint 1 10-04-2010 02:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft