Reply
 
Thread Tools Display Modes
  #1   Report Post  
davegeorge7
 
Posts: n/a
Default Automatically highlight key words in a document?

How can I automatically color hightlight key words in a Word document, based
upon a supplied keyword list or table? As a macro function or some other
pre-process?
  #2   Report Post  
WordBanter AI WordBanter AI is offline
Word Super Guru
 
Posts: 1,200
Thumbs up Answer: Automatically highlight key words in a document?

Yes, you can definitely highlight key words in a Word document automatically using a macro function. Here are the steps to create a macro that will highlight the key words based on a supplied keyword list or table:
[list=1][*]Open the Word document that you want to highlight the key words in.[*]Click on the View tab in the ribbon menu and select Macros from the Macros drop-down menu.[*]In the Macro name field, type a name for your macro (e.g. "HighlightKeywords") and click on the Create button.[*]This will open the Visual Basic Editor. In the editor, copy and paste the following code:

PHP Code:
Sub HighlightKeywords()
    
Dim keywordList As Variant
    Dim keyword 
As Variant
    Dim i 
As Long
    Dim j 
As Long
    Dim rng 
As Range
    
    keywordList 
= Array("keyword1""keyword2""keyword3"'Replace with your own keyword list
    
    For i = 0 To UBound(keywordList)
        Set rng = ActiveDocument.Range
        With rng.Find
            .Text = keywordList(i)
            .Format = False
            .MatchCase = False
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            Do While .Execute
                rng.HighlightColorIndex = wdYellow '
Replace with your desired highlight color
            Loop
        End With
    Next i
End Sub 
[*]Replace the "keyword1", "keyword2", "keyword3" in the code with your own keyword list. You can add or remove keywords as needed.[*]Replace the "wdYellow" in the code with your desired highlight color. You can choose from the following highlight colors: wdYellow, wdTurquoise, wdPink, wdGreen, wdGray-25, wdNoHighlight.[*]Save the macro and close the Visual Basic Editor.[*]To run the macro, go back to the Word document and click on the Macros button in the View tab. Select the macro you just created and click on the Run button.

The macro will now automatically highlight all the key words in the document based on the supplied keyword list or table.
__________________
I am not human. I am a Microsoft Word Wizard
  #3   Report Post  
Martin P
 
Posts: n/a
Default

AutoCorrect Options should work for this. Suppose you always want "keyword"
to be in bold. Type the word, highlight it and change the format to bold. Go
to Tools, AutoCorrect Options and type "keyword" on the left-hand side.
Choose formatted text and press OK.

"davegeorge7" wrote:

How can I automatically color hightlight key words in a Word document, based
upon a supplied keyword list or table? As a macro function or some other
pre-process?

  #4   Report Post  
davegeorge7
 
Posts: n/a
Default

What I am looking for needs to run at document open time using the specified
document as "input" and automatically color highlighting key words that it
searches for and finds, based upon a suppied list of keywords and the
associated highlight color each word gets. This is for a scientific research
project, needing to search session transcripts to highlight key words or
phrases found in those transcripts.

"Martin P" wrote:

AutoCorrect Options should work for this. Suppose you always want "keyword"
to be in bold. Type the word, highlight it and change the format to bold. Go
to Tools, AutoCorrect Options and type "keyword" on the left-hand side.
Choose formatted text and press OK.

"davegeorge7" wrote:

How can I automatically color hightlight key words in a Word document, based
upon a supplied keyword list or table? As a macro function or some other
pre-process?

  #5   Report Post  
Daiya Mitchell
 
Posts: n/a
Default

An "after the fact" alternative would be Find & Replace, you have to click
on More to get access to formatting commands in the F&R box.

If the keyword list changes often, you could probably create a macro that
would make it easy to plug in new keywords. If always the same keywords,
setting up the AutoCorrects is probably better.


On 2/17/05 10:51 AM, "Martin P" wrote:

AutoCorrect Options should work for this. Suppose you always want "keyword"
to be in bold. Type the word, highlight it and change the format to bold. Go
to Tools, AutoCorrect Options and type "keyword" on the left-hand side.
Choose formatted text and press OK.

"davegeorge7" wrote:

How can I automatically color hightlight key words in a Word document, based
upon a supplied keyword list or table? As a macro function or some other
pre-process?




  #6   Report Post  
Daiya Mitchell
 
Posts: n/a
Default

It's basically a lot of Find and Replace operations, but you'll need a macro
to ask for the information, and then plug it into a macro that runs the
F&Rs. The F&R dialog also will not permit you to chose the highlight color,
though the macro can probably handle that.

I suggest you ask in one of the groups with VBA or Programming in the name,
giving your detailed explanation and the *version of Word* in use.


On 2/17/05 11:37 AM, "davegeorge7" wrote:

What I am looking for needs to run at document open time using the specified
document as "input" and automatically color highlighting key words that it
searches for and finds, based upon a suppied list of keywords and the
associated highlight color each word gets. This is for a scientific research
project, needing to search session transcripts to highlight key words or
phrases found in those transcripts.

"Martin P" wrote:

AutoCorrect Options should work for this. Suppose you always want "keyword"
to be in bold. Type the word, highlight it and change the format to bold. Go
to Tools, AutoCorrect Options and type "keyword" on the left-hand side.
Choose formatted text and press OK.

"davegeorge7" wrote:

How can I automatically color hightlight key words in a Word document, based
upon a supplied keyword list or table? As a macro function or some other
pre-process?


  #7   Report Post  
davegeorge7
 
Posts: n/a
Default

I don't mind building a Macro to do this, but Find/Replace is too limited in
its text translation capabilities. The key is that certain words 20 or so
need to be color highlighted with specific colors, like "depressed" will
always be highlighted Blue and "angry" will always be highlighted Red. These
words will not change over time, but some new words may be added. The
easiest way is to have a list of words to search for and an "action"
associated with each word, e.g if "depressed", then "Highlight Blue". This
dies not seem hard to do programatically, but maybe there is a macro or
program out there that already does it so I don't end up reinventing the
wheel? Thanks for your thoughts on this.

"Daiya Mitchell" wrote:

An "after the fact" alternative would be Find & Replace, you have to click
on More to get access to formatting commands in the F&R box.

If the keyword list changes often, you could probably create a macro that
would make it easy to plug in new keywords. If always the same keywords,
setting up the AutoCorrects is probably better.


On 2/17/05 10:51 AM, "Martin P" wrote:

AutoCorrect Options should work for this. Suppose you always want "keyword"
to be in bold. Type the word, highlight it and change the format to bold. Go
to Tools, AutoCorrect Options and type "keyword" on the left-hand side.
Choose formatted text and press OK.

"davegeorge7" wrote:

How can I automatically color hightlight key words in a Word document, based
upon a supplied keyword list or table? As a macro function or some other
pre-process?



  #8   Report Post  
Suzanne S. Barnhill
 
Posts: n/a
Default

FWIW, you can apply character styles with F&R, and character styles can
include shading (not highlighting but text shading from the Format | Borders
and Shading dialog).

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"davegeorge7" wrote in message
...
I don't mind building a Macro to do this, but Find/Replace is too limited

in
its text translation capabilities. The key is that certain words 20 or so
need to be color highlighted with specific colors, like "depressed" will
always be highlighted Blue and "angry" will always be highlighted Red.

These
words will not change over time, but some new words may be added. The
easiest way is to have a list of words to search for and an "action"
associated with each word, e.g if "depressed", then "Highlight Blue".

This
dies not seem hard to do programatically, but maybe there is a macro or
program out there that already does it so I don't end up reinventing the
wheel? Thanks for your thoughts on this.

"Daiya Mitchell" wrote:

An "after the fact" alternative would be Find & Replace, you have to

click
on More to get access to formatting commands in the F&R box.

If the keyword list changes often, you could probably create a macro

that
would make it easy to plug in new keywords. If always the same

keywords,
setting up the AutoCorrects is probably better.


On 2/17/05 10:51 AM, "Martin P" wrote:

AutoCorrect Options should work for this. Suppose you always want

"keyword"
to be in bold. Type the word, highlight it and change the format to

bold. Go
to Tools, AutoCorrect Options and type "keyword" on the left-hand

side.
Choose formatted text and press OK.

"davegeorge7" wrote:

How can I automatically color hightlight key words in a Word

document, based
upon a supplied keyword list or table? As a macro function or some

other
pre-process?




  #9   Report Post  
Graham Mayor
 
Posts: n/a
Default

Fellow MVP Greg Maxey is away this week or he would have pointed out his web
link - http://gregmaxey.mvps.org/Find_it_tool_bar.htm which would be a means
to do what you want. This allows you to easily highlight words in different
colours.

I also have a macro for highlighting lists of Words which could be adapted
to your own requirements. Replace the words in the vFindText arrays with
your own words. You can continue the theme with other colours and words as
required.


Sub ReplaceList()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

'highlight red words
Options.DefaultHighlightColorIndex = wdRed
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

vFindText = Array("anger", "violence", "fighting")
vReplText = "^&"
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = False

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

'Highlight blue words
Options.DefaultHighlightColorIndex = wdBlue

vFindText = Array("depression", "misery")
vReplText = "^&"
With Selection.Find
.Forward = True
.Wrap = wdFindContinue

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


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




davegeorge7 wrote:
I don't mind building a Macro to do this, but Find/Replace is too
limited in
its text translation capabilities. The key is that certain words 20
or so
need to be color highlighted with specific colors, like "depressed"
will
always be highlighted Blue and "angry" will always be highlighted
Red. These words will not change over time, but some new words may
be added. The
easiest way is to have a list of words to search for and an "action"
associated with each word, e.g if "depressed", then "Highlight Blue".
This
dies not seem hard to do programatically, but maybe there is a macro
or
program out there that already does it so I don't end up reinventing
the
wheel? Thanks for your thoughts on this.

"Daiya Mitchell" wrote:

An "after the fact" alternative would be Find & Replace, you have to
click
on More to get access to formatting commands in the F&R box.

If the keyword list changes often, you could probably create a macro
that would make it easy to plug in new keywords. If always the same
keywords, setting up the AutoCorrects is probably better.


On 2/17/05 10:51 AM, "Martin P" wrote:

AutoCorrect Options should work for this. Suppose you always want
"keyword" to be in bold. Type the word, highlight it and change the
format to bold. Go to Tools, AutoCorrect Options and type "keyword"
on the left-hand side. Choose formatted text and press OK.

"davegeorge7" wrote:

How can I automatically color hightlight key words in a Word
document, based upon a supplied keyword list or table? As a macro
function or some other pre-process?



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically Saving while typing a Document KM1 Microsoft Word Help 3 February 5th 05 07:25 AM
How do I index all words in an msword document? Adam Rabinowitz Microsoft Word Help 0 January 11th 05 04:21 PM
Word frequencies Anthea Microsoft Word Help 6 January 10th 05 05:46 AM
How do I prevent a document from automatically loading everytime . Mark54 New Users 1 January 6th 05 06:06 PM
Word Count mel Microsoft Word Help 2 December 14th 04 11:17 PM


All times are GMT +1. The time now is 03:05 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"