Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. 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: Generating a Count of Word Occurrences.
by Allen Wyatt
(last updated October 28, 2017)
As you are analyzing your documents, you may wonder if there is a way to create a count of the number of words in the document. Unfortunately, Word doesn't include such a feature, but there are a couple of things you can do.
First, if you want to know the number of times a specific word or phrase is used, you can follow these steps:
Figure 1. The Replace tab of the Find and Replace dialog box.
This approach works great if you just have one or two words or phrases you want to know about. You can automate the process a bit by using a macro to search through the document and count for you. The following macro prompts the user for a word, and then counts the number of times that word appears in the document. It will continue to ask for another word until the user clicks on the Cancel button.
Sub FindWords() Dim sResponse As String Dim iCount As Integer ' Input different words until the user clicks cancel Do ' Identify the word to count sResponse = InputBox( _ Prompt:="What word do you want to count?", _ Title:="Count Words", Default:="") If sResponse > "" Then ' Set the counter to zero for each loop iCount = 0 Application.ScreenUpdating = False With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Text = sResponse ' Loop until Word can no longer ' find the search string and ' count each instance Do While .Execute iCount = iCount + 1 Selection.MoveRight Loop End With ' show the number of occurences MsgBox sResponse & " appears " & iCount & " times" End With Application.ScreenUpdating = True End If Loop While sResponse <> "" End Sub
If you want to determine all the unique words in a document, along with how many times each of them appears in the document, then a different approach is needed. The following macro will do just that.
Sub WordFrequency() Const maxwords = 9000 'Maximum unique words allowed Dim SingleWord As String 'Raw word pulled from doc Dim Words(maxwords) As String 'Array to hold unique words Dim Freq(maxwords) As Integer 'Frequency counter for unique words Dim WordNum As Integer 'Number of unique words Dim ByFreq As Boolean 'Flag for sorting order Dim ttlwds As Long 'Total words in the document Dim Excludes As String 'Words to be excluded Dim Found As Boolean 'Temporary flag Dim j, k, l, Temp As Integer 'Temporary variables Dim ans As String 'How user wants to sort results Dim tword As String ' Dim aword As Object ' Dim tmpName As String ' ' Set up excluded words Excludes = "[the][a][of][is][to][for][by][be][and][are]" ' Find out how to sort ByFreq = True ans = InputBox("Sort by WORD or by FREQ?", "Sort order", "WORD") If ans = "" Then End If UCase(ans) = "WORD" Then ByFreq = False End If Selection.HomeKey Unit:=wdStory System.Cursor = wdCursorWait WordNum = 0 ttlwds = ActiveDocument.Words.Count ' Control the repeat For Each aword In ActiveDocument.Words SingleWord = Trim(LCase(aword)) 'Out of range? If SingleWord < "a" Or SingleWord > "z" Then SingleWord = "" End If 'On exclude list? If InStr(Excludes, "[" & SingleWord & "]") Then SingleWord = "" End If If Len(SingleWord) > 0 Then Found = False For j = 1 To WordNum If Words(j) = SingleWord Then Freq(j) = Freq(j) + 1 Found = True Exit For End If Next j If Not Found Then WordNum = WordNum + 1 Words(WordNum) = SingleWord Freq(WordNum) = 1 End If If WordNum > maxwords - 1 Then j = MsgBox("Too many words.", vbOKOnly) Exit For End If End If ttlwds = ttlwds - 1 StatusBar = "Remaining: " & ttlwds & ", Unique: " & WordNum Next aword ' Now sort it into word order For j = 1 To WordNum - 1 k = j For l = j + 1 To WordNum If (Not ByFreq And Words(l) < Words(k)) _ Or (ByFreq And Freq(l) > Freq(k)) Then k = l Next l If k <> j Then tword = Words(j) Words(j) = Words(k) Words(k) = tword Temp = Freq(j) Freq(j) = Freq(k) Freq(k) = Temp End If StatusBar = "Sorting: " & WordNum - j Next j ' Now write out the results tmpName = ActiveDocument.AttachedTemplate.FullName Documents.Add Template:=tmpName, NewTemplate:=False Selection.ParagraphFormat.TabStops.ClearAll With Selection For j = 1 To WordNum .TypeText Text:=Trim(Str(Freq(j))) _ & vbTab & Words(j) & vbCrLf Next j End With System.Cursor = wdCursorNormal j = MsgBox("There were " & Trim(Str(WordNum)) & _ " different words ", vbOKOnly, "Finished") End Sub
When you open a document and run this macro, you are asked if you want to create a list sorted by word or by frequency. If you choose word, then the resulting list is shown in alphabetical order. If you choose frequency, then the resulting list is in descending order based on how many times the word appeared in the document.
While the macro is running, the status bar indicates what is happening. Depending on the size of your document and the speed of your computer, the macro may take a while to complete. (I ran it with a 719-page document with over 349,000 words and it took about five minutes to complete.)
Note that there is a line in the macro that sets a value in the Excludes string. This string contains words that the macro will ignore when putting together the word list. If you want to add words to the exclusion list, simply add them to the string, between [square brackets]. Also, make sure the exclusion words are in lowercase.
If you don't like to use macros for some reason, there are other programs you can use to create word counts. For instance, the NoteTab text editor (the "light" version can be downloaded free at https://www.notetab.com/) includes a feature that provides a word count. All you need to do is copy your entire document and paste it into NoteTab. Then, within NoteTab, choose Tools | Text Statistics | More. It presents an analysis of the word frequency, including percentages.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (10761) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Generating a Count of Word Occurrences.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!
Got a list of words you don't want to appear in your documents? There are a number of ways that you can make sure they ...Discover More
Some people, while developing documents, like to use the Highlighter tool quite a bit. It can quickly get monotonous, ...Discover More
Spend a lot of time scrolling around in your document? You might find one of Word's hidden scrolling commands to be a ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.