Selection and Deletion of Highlighted Text


L

Lola

I have a large document that multiple users will use as a template.
Depending on their use, they will need to delete certain passages of text.
Each passage is highlighted a different color. Is there a macro that can
delete certain highlighted colors?
 
Ad

Advertisements

J

Jay Freedman

I have a large document that multiple users will use as a template.
Depending on their use, they will need to delete certain passages of text.
Each passage is highlighted a different color. Is there a macro that can
delete certain highlighted colors?

You can use a series of macros, one for each color, built on this example:

Sub DeleteYellowHighlightText()
Dim oRg As Range
Set oRg = ActiveDocument.Content
With oRg
.Find.Highlight = True
While .Find.Execute
If .HighlightColorIndex = wdYellow Then
.Delete
End If
Wend
End With
End Sub

The only things that need to change from one macro to the next are the name (for
example, Sub DeleteGreenHighlightText) and the value of the HighlightColorIndex
to test (for example, wdGreen).

It would be possible to make a more complex macro in which the user could choose
the color to be deleted, and then need only one macro; but a custom toolbar with
a separate button for each color would probably be easier for most people to
use.

The one drawback of this sort of macro is that it can't be undone with a single
click of the Undo button -- there will be an entry in the Undo list for each
range that was deleted. Again, with some additional programming complexity, that
could be fixed.
 

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