Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-27-2023, 06:09 AM
syl3786 syl3786 is offline VBA Code to remove specific highlight Windows 10 VBA Code to remove specific highlight Office 2019
Advanced Beginner
VBA Code to remove specific highlight
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Default 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
And I tried many other macros for removing specific highlight colours but in vain. All of them encounter the same issue. Does any experts know how to edit the above codes so that I can use it to remove highlight colors, even though a text was highlighted in two colours?

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

Tags
highlight, macro, word vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code to remove specific highlight VBA Highlight numbers only after or before specific words help Shelley Lou Word VBA 12 08-09-2022 03:02 AM
VBA Code to remove specific highlight 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:31 PM.


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