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 / August 2005

Tip: Looking for answers? Try searching our database.

How do I setup macros to find and highlight words?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brendiux Rea - 30 Aug 2005 00:01 GMT
I am creating a macro in word 2002 to find certain words in all document and
highlight them. Word was able to do it, however, when I try to record the
macro, it does not work.
Greg Maxey - 30 Aug 2005 01:17 GMT
Something like this should get you started:

Sub myHighlighter()
Dim myWord As String
Dim rngStory As Word.Range

myWord = InputBox("Type word you want to find and highlight:")

For Each rngStory In ActiveDocument.StoryRanges
 FindAndHighlight rngStory, myWord
 Set rngStory = rngStory.NextStoryRange
Next
End Sub
Sub FindAndHighlight(ByVal rngStory As Word.Range, myWord As String)

Do Until (rngStory Is Nothing)
 With rngStory.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = myWord
   While .Execute
     rngStory.HighlightColorIndex = wdBrightGreen
   Wend
 End With
 Set rngStory = rngStory.NextStoryRange
Loop
End Sub

I have an addin that you can use it you like:

http://gregmaxey.mvps.org/Find_it_tool_bar.htm

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> I am creating a macro in word 2002 to find certain words in all
> document and highlight them. Word was able to do it, however, when I
> try to record the macro, it does not work.
Brendiux Rea - 31 Aug 2005 00:05 GMT
Thank you Greg,
I am trying to create a macro that identifies about 50 words (I will setup
them) and highlight them. I am using the following path:

Edit/find what word --> write the word that I am looking for
check mark "Highlight all items found in"
After word selects the word, I highlight them with yellow color

> Something like this should get you started:
>
[quoted text clipped - 31 lines]
> > document and highlight them. Word was able to do it, however, when I
> > try to record the macro, it does not work.
Klaus Linke - 30 Aug 2005 18:50 GMT
>I am creating a macro in word 2002 to find certain words in all
> document and highlight them. Word was able to do it, however,
> when I try to record the macro, it does not work.

Hi Brendiux,

And if "highlight" means "select", you're pretty much out of luck.

The new item (Select all instances in:...) isn't exposed in the dialog's
arguments, and there's next to no VBA support for multiple selections (...
none at all for Find).

The only option would be to use SendKeys to remote control opening the
dialog and choosing the right settings.
That might work if you only use the macro yourself, but is very fragile.

:-(  Klaus
 
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.