Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Create a search and highlight script

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Singh - 20 Mar 2008 21:52 GMT
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?
Helmut Weber - 21 Mar 2008 10:09 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.