Delete hilighted words (wdYellow)

  • Follow


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
0
Reply andreas 5/13/2010 6:05:50 PM

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 newsgroup so 
all may benefit.

andreas wrote:
> 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 


0
Reply Jay 5/13/2010 7:59:42 PM


On 13 Mai, 21:59, "Jay Freedman" <jay.freed...@verizon.net> wrote:
> You can use this:
>
> Sub DeleteYellowHighlightedText()
> =A0 =A0 Dim oRg As Range
> =A0 =A0 Set oRg =3D ActiveDocument.Range
> =A0 =A0 With oRg.Find
> =A0 =A0 =A0 =A0 .Text =3D ""
> =A0 =A0 =A0 =A0 .Format =3D True
> =A0 =A0 =A0 =A0 .Highlight =3D True
> =A0 =A0 =A0 =A0 .Forward =3D True
> =A0 =A0 =A0 =A0 While .Execute
> =A0 =A0 =A0 =A0 =A0 =A0 If oRg.HighlightColorIndex =3D wdYellow Then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 oRg.Delete
> =A0 =A0 =A0 =A0 =A0 =A0 End If
> =A0 =A0 =A0 =A0 =A0 =A0 oRg.Collapse wdCollapseEnd
> =A0 =A0 =A0 =A0 Wend
> =A0 =A0 End With
> End Sub
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP =A0 =A0 =A0 =A0FAQ:http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup=
 so
> all may benefit.
>
>
>
> andreas wrote:
> > 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- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Hi Jay,

this did the trick. Great help from your side. Thank you very much.
Regards, Andreas
0
Reply andreas 5/14/2010 2:26:52 PM

2 Replies
388 Views

(page loaded in 0.058 seconds)

Similiar Articles:







7/25/2012 11:34:56 PM


Reply: