Written by Allen Wyatt (last updated July 29, 2023)
This tip applies to Word 97, 2000, 2002, and 2003
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:
Word shows you, in the dialog box, how many occurrences it located of your word or phrase. This technique, while handy, loses some of its 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/kb/240157
The code in this page could 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:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (333) applies to Microsoft Word 97, 2000, 2002, and 2003.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!
The no-width optional break is primarily used for Asian languages in Word. It can have value for English-speakers, as ...
Discover MoreA common task when editing documents is to break up run-on sentences. You can make this task a little easier by using the ...
Discover MoreWant a little more space just before some of your punctuation characters? You can add that spacing in a variety of ways, ...
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 © 2025 Sharon Parq Associates, Inc.
Comments