Consulting

Results 1 to 4 of 4

Thread: Clear specific highlighting

  1. #1

    Clear specific highlighting

    I'm trying to get the following code to work to clear highlighting of a specific color. Not sure what I'm doing wrong for it to scan the entire document for all instances of the color highlighting and remove it:

    Sub remove_highlight()
    '
    ' remove_highlight Macro
    '
    '
        Dim hiliRng As Range
        Set hiliRng = ActiveDocument.Range
       With hiliRng.Find
            .Highlight = True
            .Execute
                If hiliRng.HighlightColorIndex = wdColorTan Then
                    hiliRng.HighlightColorIndex = wdNoHighlight
                End If
        End With
    End Sub

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    There is no such thing as wdColorTan as a highlight color index.

    Sub remove_highlight()
         '
         ' remove_highlight Macro
         '
         '
        Dim hiliRng As Range
        Set hiliRng = ActiveDocument.Range
        With hiliRng.Find
            .Highlight = True
            While .Execute
              MsgBox "Found highlight " & hiliRng.HighlightColorIndex
            If hiliRng.HighlightColorIndex = wdColorTan Then
                hiliRng.HighlightColorIndex = wdNoHighlight
            End If
            Wend
        End With
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    My post count is too low to post links, but reference the existence of wdColorTan here: msdn.microsoft[dot]com/en-us/library/bb237558(v=office.12).aspx

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    I didn't say or even suggest that there was no such thing as a color constant wdColorTan. I said that there was no .hightlightcolorindex wdColorTan. Maybe your text is not highlighted but shaded instead.

    Sub remove_TanShading()
    Dim oRng As Range
    Set oRng = ActiveDocument.Range
      With oRng.Find
        .Text = ""
        .Format = True
        .Font.Shading.BackgroundPatternColor = wdColorTan
         While .Execute
           If oRng.Font.Shading.BackgroundPatternColor = wdColorTan Then
             oRng.Font.Shading.BackgroundPatternColor = wdColorAutomatic
             oRng.Collapse wdCollapseEnd
           End If
         Wend
      End With
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •