How to find a series of words and then changing formats

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a large Word document in which I would like to 1) find out if the
document contains specific words, which I have listed in a separate document
and 2) highlight by bold or underline any occurence of the select words in
the document.

Is there a way for me to do this automatically. I would like to easily
identify the incidence of the select words in the document without having to
read and highlight the document, as I know that I will miss many incidences
of the words.
 
You can do this with the Replace function. Let's suppose you want to
highlight all occurrences of the word "document." Type that word into the
"Find what" box. Type it again in the "Replace with" box, but this time
click More. Select Format-highlight (or underline--use Format-font), then
click Find next. Try it on two or three replacements; if OK, click Replace
all. You can do the same for strings of words. You may be better off using
underline unless you have color printers to show the highlighting.

You may have to use "whole words only" because the plural, documents, would
otherwise not have the terminal "s" highlighted or underlined. Same would be
true of documentation, documented, etc. This is not a problem with strings,
if, for instance, you wanted to select "the contract document." You may also
have to watch for capitalized "Document," which could start a sentence.
 
Richard, Thank you for your response! I have though about 100 unique words
that I am looking for. Is there a way that I could find-replace any
incidence of the words at one time. Or am I stuck doing find-replace ~100
times for all the words that I am looking for.

Thanks again!! I welcome your continued advice and help!!
 
You are stuck doing it 100 times, because the Replace function can handle
only one word or string at a time. In other words, you can't "replace" the
words "document," "page," or "line" all at once unless they are in a string,
such as "on the first line of every page in this document..."
 
That's not strictly true - you could set up a macro containing an array of
the 100 words and run the replacement function on those 100 words. The
following is an example, using 6 words, but provided you don't try and pile
them all on one line, you can use 100 words.

Sub ReplaceList()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

vFindText = Array("Word1", "Word2", "Word3", _
"word4", "Word5", "etc")
With Selection.Find
.ClearFormatting
.Wrap = wdFindStop
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.ClearFormatting
.Replacement.Text = "^&"
.Replacement.Highlight = True
.Execute replace:=wdReplaceAll
Next i
End With
End Sub

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


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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

Back
Top