Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Checking for Words and Phrases.

Checking for Words and Phrases

Written by Allen Wyatt (last updated August 1, 2023)
This tip applies to Word 2007, 2010, and 2013


3

David is a teacher who assigns his students a series of about twenty words and phrases that they must use in a composition. Each word or phrase must be used at least once. The students get one point for each time they use one of the words or phrases, although nothing extra for duplicates. David is looking for an easy way to mark their work, perhaps with a macro that searches for each word and phrase and creates some sort of record of their usage. Dave's desire is for Word to do the searching and counting so that he can focus his energy on assessing the quality of the composition.

If you want to manually figure out how many occurrences there are of a particular word or phrase, you can use Word's Find feature. Follow these steps if you are using Word 2007:

  1. Press Ctrl+F. Word displays the Find tab of the Find and Replace dialog box.
  2. In the Find What box, enter the word or phrase you want to find.
  3. Click the More button, if it is available.
  4. If you are searching for a single word, click the Find Whole Words Only check box.
  5. Click the Highlight All Items Found check box.
  6. Click Find All.

Word shows you, in the dialog box, how many occurrences it located of your word or phrase. You can find the desired counts even faster if you are using Word 2010 or Word 2013:

  1. Press Ctrl+F. Word displays the Navigation task pane at the left side of the screen. In the pane the Browse tab is selected.
  2. If you are searching for a single word, click the down-arrow at the right of the small magnifying glass button and choose Options. In the Options dialog box choose Find Whole Words Only.
  3. In the box at the top of the Navigation pane, enter the word or phrase for which you want to find and press Enter.

Word shows you, at the top of the Navigation task pane, how many occurrences it located of your word or phrase.

These techniques, while handy, lose some of their charm if you need to repeat it for twenty words and phrases in thirty-five different student compositions. Indeed, a macro is a more practical approach.

It would be very convenient if the number of occurrences displayed in the Find and Replace dialog box was accessible through VBA. As far as I have been able to determine, this value is not accessible. That means that you must rely on repeated searching and counting in the macro itself. One good example of how this can be done is found in the Microsoft Knowledge Base:

http://support.microsoft.com/?kbid=240157

The page indicates that the code is for Word 2000, but it will work just fine with Word 2007 and Word 2010. The code in this page can be changed, relatively easily, to search for a series of words or phrases and display all the results at once. Another rather unique approach is to reverse the assumptions about the student compositions: assume that they use each of the words or phrases (they start with a score of 20 if there are twenty words and phrases) and only subtract points if they don't use one of them.

Sub ScoreCard()
    Dim iScore As Integer
    Dim iTopScore As Integer
    Dim WordList As Variant
    Dim i As Integer
    Dim sUnused As String

    ' Enter the words or phrases in the array below;
    ' each word or phrase in quotation marks and
    ' separated by commas
    WordList = Array("Mr.", "jelly", "wince", _
      "proper", "fix", "compound", "high and dry")

    ' Counts the number of words in the array
    iTopScore = CInt(UBound(WordList)) + 1
    iScore = iTopScore

    ' Counts the number of "misses"
    sUnused = ""
    For i = 1 To iTopScore
        With Selection.Find
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchAllWordForms = False
            .MatchWholeWord = True
            .Execute FindText:=WordList(i - 1)
        End With
        If Selection.Find.Found = False Then
           iScore = iScore - 1
           sUnused = sUnused & vbCrLf & WordList(i - 1)
        End If
    Next i

    ' Displays the score
    If iScore = iTopScore Then
        sUnused = "All words and phrases were used."
    Else
        sUnused = "The following words and phrases" & _
          " were not used:" & sUnused
    End If
    sUnused = vbCrLf & vbCrLf & sUnused
    MsgBox Prompt:="The score is " & iScore & _
      " of " & iTopScore & sUnused, Title:="What's the Score?"
End Sub

The macro displays a score for the composition and also displays any of the words or phrases that were not used in the composition.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9261) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Checking for Words and Phrases.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

TOC Heading Numbers Always Show in Bold

Linda's got a document that includes a table of contents that is based on headings in the document. When the headings ...

Discover More

Using Strikethrough Formatting

Need a line through the middle of your text? Use strikethrough formatting, which is easy to apply using the Format Cells ...

Discover More

Associating a Name with a Position

Wouldn't it be great if Word allowed you to have a small pop-up that showed you some information associated with a ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Talking to Yourself

Need to keep notes about a document, but you don't want others to see those notes either on-screen or on-paper? Here's an ...

Discover More

Deleting Freezes Computer

Sometimes a strange object or text may appear in your document, as happened to Sharon. To complicate the situation, her ...

Discover More

Inconsistent Availability of Drag and Drop Editing

Some people really like the ability to drag and drop text as they edit. What do you do if the ability is only available ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 7?

2016-09-21 14:28:58

Abu Baker A. A. Al Hadi

My word (2013) does not show the number of the word occurrences. It some times delete the word from the search pane. Any solution?
Thank you


2015-11-16 10:17:34

Ewart

hi I have a big/lengthy Ms. Office document, I want to develop a way of making it easy to find different heading, word.

The scenario I am trying to implement is where if I may need to speak on or reference a specific part of the content. I can easily find it by typing a word, phrase. without scrolling through over 70+ pages.

I will greatly appreciate your urgent help.

Thank you.


2014-08-02 05:02:31

PeterJ

This is OK, but you need to change the code every time the word list changes. In this case, every week when the essay topic changes!

A more elegant and flexible way is to hold your Word (or phrase) list in a simple '.txt' file one per line. Then all you need to do is to read the file into the WordList array.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.