Delete hilighted words (wdYellow)

A

andreas

Dear Experts:

I did some highlighting in a document using different colors (wdYellow
and wdBlue).

I now would like to delete all words/characters that have been
highlighed yellow and leave the blue ones alone.

How can I achieve this using a VBA code?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
 
J

Jay Freedman

You can use this:

Sub DeleteYellowHighlightedText()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.Text = ""
.Format = True
.Highlight = True
.Forward = True
While .Execute
If oRg.HighlightColorIndex = wdYellow Then
oRg.Delete
End If
oRg.Collapse wdCollapseEnd
Wend
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
A

andreas

You can use this:

Sub DeleteYellowHighlightedText()
    Dim oRg As Range
    Set oRg = ActiveDocument.Range
    With oRg.Find
        .Text = ""
        .Format = True
        .Highlight = True
        .Forward = True
        While .Execute
            If oRg.HighlightColorIndex = wdYellow Then
                oRg.Delete
            End If
            oRg.Collapse wdCollapseEnd
        Wend
    End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroupso
all may benefit.









- Zitierten Text anzeigen -

Hi Jay,

this did the trick. Great help from your side. Thank you very much.
Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top