keyword Search Macro?!?

S

stacy05

I would like to create a macro or some other kind of function that
automatically highlight keywords when I open a document. Is that a capability
within Word, or is there an outside resource anyone knows of that can
accomplish this?

Thanks!
Stacy
 
G

Graham Mayor

The following macros will highlight (and remove the highlight) from a list
of words set in quotes and separated by commas in the line vFindText =


Sub HighlightList()
Dim rDcm As Range
Dim vFindText As Variant
Dim i As Long
Set rDcm = ActiveDocument.Range
'*************************************************
vFindText = Array("Lorem", "dolor", "amet")
'*************************************************
'Selection.HomeKey Unit:=wdStory
With rDcm.Find
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True

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

Sub RemoveHighlight()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = ""
.Highlight = True
.Replacement.Text = "^&"
.Replacement.Highlight = False
.Execute replace:=wdReplaceAll
End With
End Sub

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


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


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

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