Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2024, 09:18 AM
Shelley Lou Shelley Lou is offline VBA Remove specific colour highlight Windows 10 VBA Remove specific colour highlight Office 2016
Expert
VBA Remove specific colour highlight
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Remove specific colour highlight

I found the code below searching through this forum that Greg Maxey created to remove specific colour highlighting. I'm trying to update the code to remove both BrightGreen and Pink highlighting within a document. It seems to be working ok but just wanted to make sure I've added to the code correctly? Thanks.




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 = wdBrightGreen Then
              oChr.HighlightColorIndex = wdAuto
            End If
          'Next
          If oChr.HighlightColorIndex = wdPink Then
              oChr.HighlightColorIndex = wdAuto
            End If
          Next
        Case Is = wdBrightGreen
          oRng.HighlightColorIndex = wdAuto
Case Is = wdPink
          oRng.HighlightColorIndex = wdAuto
      End Select
      oRng.Collapse wdCollapseEnd
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
Reply With Quote
  #2  
Old 11-13-2024, 12:04 PM
gmaxey gmaxey is offline VBA Remove specific colour highlight Windows 10 VBA Remove specific colour highlight Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Shelly Lou,


Looks fine. I would do it like this using the Select statement:

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
            Select Case oChr.HighlightColorIndex
              Case wdBrightGreen, wdPink
              oChr.HighlightColorIndex = wdAuto
            End Select
          Next oChr
        Case Is = wdBrightGreen
          oRng.HighlightColorIndex = wdAuto
        Case Is = wdPink
          oRng.HighlightColorIndex = wdAuto
      End Select
      oRng.Collapse wdCollapseEnd
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-18-2024, 02:13 AM
Shelley Lou Shelley Lou is offline VBA Remove specific colour highlight Windows 10 VBA Remove specific colour highlight Office 2016
Expert
VBA Remove specific colour highlight
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Remove specific colour highlight

Thanks so much for looking at the code and making the adjustment, very much appreciated and works a treat.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Remove specific colour highlight VBA Code to remove specific highlight syl3786 Word VBA 4 03-27-2023 05:01 PM
VBA Remove specific colour highlight Remove highlight with specific color rekent Word VBA 2 08-01-2020 10:59 AM
MS Project: Network Diag view: Task Cell background colour (Highlight) stct Project 0 10-17-2017 07:37 AM
VBA Remove specific colour highlight How do I select all text highlighted in a specific colour? bertietheblue Word 2 04-15-2016 12:30 PM
changing the colour of text box highlight in PowerPoint v.x miki PowerPoint 1 11-16-2010 02:06 AM

Other Forums: Access Forums

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


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