Find and replace a specific highlighted color in a selected text to a different color

G

Guest

I have a large block of text in a word-document. In this block of text some letters are highlighted (background color black)
Is it possible to use the find and replace-feature to search for only the highlighted background color (e.g. black) but ignoring the text in front, and then replacing the black color with a different color - thereby not changing the highlighted text, but only the color of the text highlighted in black

The text-block I have is an alignment of amino-acid-sequences. Each letter resembling an amino acid. The color-highlights marks amino acid resemblance/similarity. Black is great resemblance, gray is poor resemblance.
Because the text denotes amino acid sequences, it is essential that the text remains unaltered and only the background is changed
I would like to change all letters highlight-colored in black (and only the letters colored black) to be the same letters but with their highlight-color changed to a different color

I would be very gratefull if anyone is able to help m

Steen
 
G

Guest

Hi Steen

Unfortunately, you cannont search for a specific highlighting color, only whether or not the text is highlighted at all. It is possible to do what you're asking using the Find object in VBA, but it's not easy (well, not for me, and not as easy as giving you a simpler, but slower, solution)

Go to Tools -> Macro -> Macro
In the box marked "Macro Name:" put in "ChangeBlackHighlightToBlue" (or something similarly descriptive), and press "Create

You'll see something like this

========
Sub ChangeBlackHighlightToBlue(

' ChangeBlackHighlightToBlue Macr
' Macro created 4/28/2004 by Stee


End Su
========

Now put you cursor on the line just above the one that says "End Sub", and type in the following

Dim char As Rang
Application.ScreenUpdating = Fals
For Each char In ActiveDocument.Character
If char.HighlightColorIndex = wdBlack The
char.HighlightColorIndex = wdBlu
End I
Next cha
Application.ScreenUpdating = Tru

So that your final macro looks like this
=====================
Sub ChangeBlackHighlightToBlue(

' ChangeBlackHighlightToBlue Macr
' Macro created 4/28/2004 by Stee

Dim char As Rang
Application.ScreenUpdating = Fals
For Each char In ActiveDocument.Character
If char.HighlightColorIndex = wdBlack The
char.HighlightColorIndex = wdBlu
End I
Next cha
Application.ScreenUpdating = Tru
End Su
======================

While still in the Visual Basic Editor, go to File --> Save, then File --> Close and Return to Word

Now with the document in question open, go to Tools -> Macro -> Macros, select the macro you just created, and press "Run"

WARNING: If the document you're working on is long (more than a few pages), this may take some time to run. It has to iterate over every single character, and that takes a while. Be patient. If your document is *really* long, this may not be a suitable solution. But why not just sit back and let Word do the work

BTW, the macro above changes the black to blue. If you want to use a different color, replace the "wdBlue" with the color you want (the other options are wdBlack, wdYellow, wdRed, wdDarkRed, wdDarkBlue, wdGreen, wdBrightGreen, wdPink, wdDarkYellow, wdTeal, wdTurquoise, wdViolet, wdGray25, and wdGray50)

HTH
Andrew Savika
O'Reilly Media, Inc

----- Steen wrote: ----

I have a large block of text in a word-document. In this block of text some letters are highlighted (background color black)
Is it possible to use the find and replace-feature to search for only the highlighted background color (e.g. black) but ignoring the text in front, and then replacing the black color with a different color - thereby not changing the highlighted text, but only the color of the text highlighted in black

The text-block I have is an alignment of amino-acid-sequences. Each letter resembling an amino acid. The color-highlights marks amino acid resemblance/similarity. Black is great resemblance, gray is poor resemblance.
Because the text denotes amino acid sequences, it is essential that the text remains unaltered and only the background is changed
I would like to change all letters highlight-colored in black (and only the letters colored black) to be the same letters but with their highlight-color changed to a different color

I would be very gratefull if anyone is able to help m

Steen
 

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