There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Business Applications
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Macro that finds and highlights specific words in MS Word document


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
enars's Avatar
Junior Member with 2 posts.
 
Join Date: Jul 2008
10-Jul-2008, 06: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 580 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
10-Jul-2008, 09: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!
__________________
The BestS
AJ
enars's Avatar
Junior Member with 2 posts.
 
Join Date: Jul 2008
11-Jul-2008, 02: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 580 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
11-Jul-2008, 03: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 580 posts.
 
Join Date: Sep 2007
Location: Moldova
Experience: Intermediate
11-Jul-2008, 03:02 AM #5
If it's all you can mark thread as solved, using thread tools
Plantsman's Avatar
Senior Member with 182 posts.
 
Join Date: Jan 2008
Experience: Intermediate
11-Jul-2008, 11:30 AM #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


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

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 05:45 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.