find/replace with font color

V

VitaminL

Hi, I'm a freelance translator who uses Word all the time but still
knows shamefully little about its advanced features : (

I've wasted most of my morning trying to concoct a macro so I thought
I'd come here for advice.

I'd like to be able to:

1) Highlight a word
2) Hit a button
3) Have all instances of that word change red.

I feel certain that this can be done, I just can't figure out how to do
it. Right now it's a several step process using ctrl + H. I'd like to
make it a one step process.

Any help would be appreciated.

Thanks

~ vitaminL
 
S

Suzanne S. Barnhill

I'm not sure why it would be a several-step process with Replace. That is,
it requires only a single Replace action:

1. In the Replace dialog, type the word (or paste it using Ctrl+V) in the
"Find what" box.

2. Click More.

3. With the insertion point in the (blank) "Replace with" box, click Format
| Font and choose Font color: Red.

4. Replace All.
 
G

Graham Mayor

How about the following which will turn red all words that match the word at
the cursor. If you want the search to be case sensitive change the line
..MatchCase = False
to
..MatchCase = True


Sub TurnEmRed()
Dim sFindText As String
sFindText = Selection.Words(1)
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'**********************
.Text = sFindText
.Replacement.Text = "^&"
.Replacement.Font.Color = wdColorRed
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute replace:=wdReplaceAll
End With
End With
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
V

VitaminL

Thanks for the help! That macro is almost perfect, I work with Chines
text so it sometimes has difficulties with determining when words star
and stop. Is there an easy way to change it to search and replace onl
for the text I've selected (highlighted)?

Thanks again,

Vitamin
 
G

Graham Mayor

Change the line
sFindText = Selection.Words(1)
to
sFindText = Selection

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
V

VitaminL

Works a charm.

Thank you very much~

vitaminL
Change the line
sFindText = Selection.Words(1)
to
sFindText = Selection

--

Graham Mayor - Word MVP

My web site www.gmayor.com



VitaminL wrote:-
Thanks for the help! That macro is almost perfect, I work with
Chinese
text so it sometimes has difficulties with determining when words
start and stop. Is there an easy way to change it to search and
replace only for the text I've selected (highlighted)?

Thanks again,

VitaminL -
 

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