Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Macro that finds and highlights specific words in MS Word document

Reply  
Thread Tools
enars's Avatar
Junior Member with 2 posts.
 
Join Date: Jul 2008
10-Jul-2008, 07:12 AM #1
Question Solved: Macro that finds and highlights specific words in MS Word document
I need a macro that finds a specific word in a text and highlights it. For example, I would like to find a word "computer" in some text and make all words "computer" in red color. Can anybody help me to create such macro for Ms Word?
Aj_old's Avatar
Computer Specs
Senior Member with 869 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
10-Jul-2008, 10:47 AM #2
hi and welcome!
You don't need a macro for this!
Go to MS Word, Ctrl+H (or Edit\Replace... ), in the field Find What type your text, for example "Computer"
in the field Replace with type nothing (leave it empty),press the More Button, put the cursor in it Replace With field, and press the button Format, and select Highlight option (bellow the Replace With field you'll see the text "Format: Highlight"
Now press the Replace All button!
__________________
“I hear, I know. I see, I remember. I do, I understand.” (Confucius 551 BC – 479)
enars's Avatar
Junior Member with 2 posts.
 
Join Date: Jul 2008
11-Jul-2008, 03:19 AM #3
solved
Hi Aj_old,

Thanks for reply! I followed your instructions and recorded a macro that looks like this:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.highlight = True
With Selection.Find
.Text = " "" "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow


In this example it highlights any quotation mark (") that has spaces before and after. I use it for checking spelling errors and deciding which space is unnecessary.

Regards,

Enars http://www.hotelbooklet.com
Aj_old's Avatar
Computer Specs
Senior Member with 869 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
11-Jul-2008, 04:02 AM #4
Hi glad that my post helped!
You can replace the line
Code:
 .Text = " "" "
in your code with this one:
Code:
 .Text = Inputbox("Type in the text you wanna be highlighted")
so you could do the same with any text, without having to modify each time your code!
Aj_old's Avatar
Computer Specs
Senior Member with 869 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
11-Jul-2008, 04:02 AM #5
If it's all you can mark thread as solved, using thread tools
Plantsman's Avatar
Member with 422 posts.
 
Join Date: Jan 2008
Experience: Intermediate
11-Jul-2008, 12:30 PM #6
if you want to highlight general spelling errors here's a Macro for that also.

The following macro highlights any misspelled words:


Sub HighlightMisspelledWords()
Dim oWord As Range
Dim StoryRange As Range
For Each StoryRange In ActiveDocument.StoryRanges
Application.CheckSpelling Word:=StoryRange
For Each oWord In StoryRange.Words
If Not Application.CheckSpelling(Word:=oWord.Text) Then
oWord.HighlightColorIndex = wdYellow
End If
Next oWord
Next StoryRange
End Sub



Clear all highlighting from a document.
The following macro clears highlighting from all words:


Sub ClearHighlightFromAllWords()
Dim StoryRange As Range
For Each StoryRange In ActiveDocument.StoryRanges
StoryRange.HighlightColorIndex = wdNoHighlight
Next StoryRange
End Sub
__________________
Plant something for Earth's sake.
Reply

Tags
find, highlight, macro, text, word

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:08 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.