Create a search and highlight script

S

Singh

Is it possible to create a script to search through a body of text and find
and highlight all instances of a predefined list of words?

i.e. I have a list of 25 words... can I click a button and have Word
highlight wherever those words appear?
 
H

Helmut Weber

Hi Singh,

like that:

Sub Test4b()
Dim sArr() As String
Dim rTmp As Range
Dim x As Long
sArr = Split("the brown jumps dog") ' your list
Options.DefaultHighlightColorIndex = wdYellow
For x = 0 To UBound(sArr)
Set rTmp = ActiveDocument.Range
With rTmp.Find
.Text = sArr(x)
.Replacement.Text = sArr(x)
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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