Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Highlight Words from a Word List.
Written by Allen Wyatt (last updated September 11, 2021)
This tip applies to Word 97, 2000, 2002, and 2003
Paul has a document that he needs to check against a word list contained in another document. If the document being checked contains one of the words in the list, then the word in the document (not in the word list) needs to be highlighted by being made bold. The word list is large, on the order of 20,000 words, and Paul is wondering what the best way to do this is.
There are two ways you can proceed. The first is to write your own macro that will do the comparisons for you. If you put the words you want checked into a document named "checklist.doc" in the C: drive, then the following macro can be used:
Sub CompareWordList() Dim sCheckDoc As String Dim docRef As Document Dim docCurrent As Document Dim wrdRef As Object sCheckDoc = "c:\checklist.doc" Set docCurrent = Selection.Document Set docRef = Documents.Open(sCheckDoc) docCurrent.Activate With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Font.Bold = True .Replacement.Text = "^&" .Forward = True .Format = True .MatchWholeWord = True .MatchCase = True .MatchWildcards = False End With For Each wrdRef In docRef.Words If Asc(Left(wrdRef, 1)) > 32 Then With Selection.Find .Wrap = wdFindContinue .Text = wrdRef .Execute Replace:=wdReplaceAll End With End If Next wrdRef docRef.Close docCurrent.Activate End Sub
All you need to do is have the document open that you want checked, and then run the macro. If the document containing the words to check is named differently or in a different location, just change the line that sets sCheckDoc so that it has a different full path name for the document.
Basically, the macro grabs each word from the word list and then does a Find and Replace operation using that word in the document. If you have many, many words in the word list, then the macro can take quite a while to run—20,000 Find and Replace operations is quite a few!
The other approach you can try is to use a third-party application to do the work for you. There is a good article and application available free at this site:
http://pubs.logicalexpressions.com/pub0009/LPMArticle.asp?ID=160
This approach is particularly interesting because it doesn't just make matched words bold, but allows you to set them to some color that you may desire.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (502) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Highlight Words from a Word List.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
If you need to move the insertion point within your macro, then you'll want to note the HomeKey method, described in this ...
Discover MoreWhen creating macros, you often need to offer a series of choices to a user. This tip demonstrates how easy it is to ...
Discover MoreWhen a macro works with files, it often has to change between different directories on your disk drive. This is done ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments