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.
Written by Allen Wyatt (last updated April 10, 2023)
This tip applies to Word 2007, 2010, 2013, and 2016
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.
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 (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.
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!
If you use a lot of acronyms in your documents, you may want a quick way to compile those acronyms and their definitions ...
Discover MoreCross-referencing has long been a capability in Word documents. You can easily add and remove cross-references but ...
Discover MoreIf you decide to create a master document, it is easy to do by just adding one or more subdocuments to an existing ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-03-26 01:35:22
Jen
Will this work for Version 16.83 (word for Mac)?
If not what can I use to achieve a list of words, the frequency of their use? Putting the list into a table is really cool but I would be happy with just a list.
2024-01-12 12:43:55
Carolin
The macro for word frequency is brilliant. I am writing my dissertation in Law and this will be very helpful in my analysis of cases and articles.
While the list of excluded words is useful, is it possible to specify a set of words that excludes ALL EXCEPT the included words? Doing tFor example, I would like to count the occurrence of only
2023-06-21 15:28:52
Pat Shaw-Allen
I would like to use the macro to count acronyms of two or more letters. I have not been able to figure out how to modify the exclude statement. I used
Excludes = "[<[a-z]{1,}>]"
and
SingleWord = Trim(aword)
to no avail
2023-04-10 07:48:01
Ilana
You can also use the Find tab. In the later versions of Word, Ctrl + f opens a sidebar, but if you go to Ctrl + h and open the Find tab from there (see Figure 1 in the article), you can find your word that way. The key is to use the alternate options: Find In (which gives you Current Selection, Main Document, Footnotes, and Comments). You can Highlight All. Or you can jump through them by using Find Next (although the sidebar is a better solution to see all the instances). You still have all the options through the More button.
So if you are looking for your word, you'll open the options for Find In (Main Document). Then the number of instances is revealed at the bottom of the white space under the "Find What" box.
With this method, you are not replacing any text.
(Also, out of curiosity, I closed the Find dialogue box, and it left the words highlighted. Then I went to the Word Count box via that ribbon, and it gave me the same number of instances.)
2023-02-22 10:04:29
Pat
Hello
You always have the best stuff! Is there any way I can ensure that the capitalization is retained when using the Sub WordFrequency() macro? I would like to use it to spot unecessary acronyms (i.e. if used less than 5 times, write out the word)
thanks
2023-01-17 13:45:07
This is amazing, thank you!
just wondering, would it be possible, instead of counting every single word, it can refer to a list of short phrases instead? Essentially I'm trying to automate the process of generating a glossary, so I need a count of words or multiple words or acronyms.
Thanks again!
Steve
2021-10-17 11:53:50
VBA
Hi,
What about the compound words, like "well-dressed"?
The macro counts two words ("well" and "dressed") and ignores the compound word "well-dressed".
Thanks!
2021-10-05 07:57:17
How could I change this macro to include Korean characters in the word count?
2021-09-20 04:49:22
KE
Paul
The problem is that many words end in "s" but are not plural. It would be nice to be able to use the spelling dictionary which can distinguish plurals but it is in coded form (however, the custom dictionary is stored as text).
The best that can be done is to sort the words alphabetically which will put consecutively the two versions of the word.
2021-09-19 04:42:05
Paul Z.
Singular and plural word forms are counted as separate words. A contraction and its root word are also counted as separate words. How can I modify the macro so that they can come out as one word?
2021-06-28 04:46:06
The macro does not include words beginning with "z" for some reason.
Can this be changed please.
2021-06-09 10:09:52
Navneet Rafaliya
What modifications I would have to make to macro for it to work for another language? I am trying to do it for 'Gujarati' and dialogue box shows: There were 0 different words.
This is how gujarati looks like
ધોળી છીંટની ડગલી પહેરી હતી તથા ધોળો સુરવાળ પહેર્યો હતો તથા ધોળો ફેંટો મસ્તક ઉપર બાંધ્યો હતો ને પોતાના
2020-11-18 20:27:09
Philip Bennett
I really enjoyed using this WORD+FREQ Macro for Word.
Can it be modified to include numerals in the count? i.e. show frequencies for the numerals 0-9 in a piece of text?
2020-11-13 15:45:39
Doug
If you run the macro, it will give you a list of all the words and their number of occurrences, so you would see all those related words like march, marched, marches etc. together. It also will show you words as they occur, so misspellings appear as well...very handy for a word close to march but misspelled.
2020-11-12 12:30:07
J Harwell
How would I modify word count macro for unique words to include the count for a list of specific words or acronyms that I specify. It seems like a set of commands that says only list words between [brackets] would be needed somewhere to accomplish this task.
2020-11-01 14:27:47
Malcolm
Thanks for the Tip. It looks great.
One Question:
Is there any way for it to pick up on words where there are different forms of basically the same word, e.g. plurals and singulars (tree and trees), possessive forms (palace and palace's), verb forms (march, marched, marches, marching) and group the different forms together?
2020-10-16 03:24:58
Ken
After Or on the same line add a space and underscore.
They setup continuation onto the next line.
2020-10-15 20:06:44
Abraham Hernandez
Hello, I am new to macros and tried running bu got a syntax error in the last two lines below.
WOuld you mind helping me fix it?
' 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
2020-08-09 18:41:29
Valery Belyanin
' Set up excluded words
Excludes = "[the][a][of][is][to][for][by][be][and][are]"
I need to exclude more words, but the strings should be short and i can not make a long string. is there a solution like?
' Set up excluded words
Excludes = "[the][a][of][is][to][for][by][be][and][are]"
' Set up excluded words
Excludes = "[one][twof]three]"
It did not work for me though
2020-07-02 09:32:25
Andrew
Tjasa - Subject to what Ken said, you can try changing the line
SingleWord = Trim(LCase(aword))
to
SingleWord = Trim(aword)
Then when you sort by WORD all the similar words should be together in the list . Or you could use Words sort mechanism to re-sort the list. There are a lot of subtleties to selecting and sorting words, so you might not get quite what you want, but this could be a good start.
2020-07-01 03:59:52
Ken
The problem with producing a case sensitive count is that a word can be capitalised at the start of a sentence but not in the body in which case it would be meaningless to list as two different words. The best that could be done would be to list separately words that have all capitals.
2020-06-30 17:56:55
Tjasa
Thanks for the tip.
I would like to use the frequency option but with case sensitive results.
2020-05-09 20:46:13
Aziz
Thank you so much for this precious tip. The only concern I have is that this tip did not work with Right-to-left languages.
Any suggestion for that?
Thank you in advance,
2020-03-13 15:32:23
David Cohen
Here's another easy way to get a word count with search and replace. First, create a copy of the document and use it just as a working piece. Enter the same word in both the search and replace boxes. Change the format of the font of replaced word (red, bold, whatever). As noted above, Word will tell you how many words have been replaced (thus, how many occurrences). And then you can scroll through the document and easily spot the occurrences. If you are working with the original document, not a working document, you can undo the format change.
2020-03-12 14:11:31
Glen Slee
Much appreciate the Tip, and your group that I have 'been with' since the late '90's - I have learnt heaps (even though a lot of Q&A is over-my-head: stuff for which I have no immediate need; but when I do have a Q, I feel very comfortable in asking).
2019-09-13 10:13:00
User2019
Thank you.
2019-09-09 18:00:34
Sandra
Oh my goodness, THANK YOU! I copied and pasted the macro to find and count frequency of all repeated words and it worked like a charm! Thank you for this! (When your company mentions itself 150 times ina proposal....there's a problem. HaHa!)
2019-08-11 08:03:18
Robert Kinnell
Hi will there be an update on this VBA macro as their seems to be errors running from word 2019
2019-06-12 13:58:35
Tien
Hi Allen,
Thanks for creating these macros as they work great! How would I implement a case-sensitive search for the word frequency macro? There's not much information on forums or other sites to explain any sort of usage for Word VBA scripts.
Thanks!
2019-06-08 05:24:58
Timo Ericsson
Thanks! This macro was just what I needed and worked with Word for Mac 2016.
2019-06-08 00:24:27
Phiodias Marthias
For me, not IT guys, not familiar with VBA, it is a great formula. It is very helpful to accomplish my task.
Thank you so much.
2019-05-14 17:19:55
Giorgi
Hello,thanks for this article. As I tried it worked with the English Text but did not do so with texts of other encoding for example for Georgian text (utf 8). Any solution ?
Thanks in advance for your attention
2019-02-27 20:13:11
PWT
Thank you, Allen Wyatt, for all your wonderful articles. The Find and Replace With tip of using ^? is something I use on a daily basis. It has saved me so much time that I say a little prayer for you every time I use it. Before ^?, I copied the Find value into the Replace With field to guard against typos. How did ^? come to your attention? Except for your article, I can't find anything about it. Are there other hidden gems akin to ^? that are virtually unknown?
2019-02-07 16:46:52
Doug Loud
This is very helpful, but in very long documents it comes up with a long list. In Word 2016 Is there a way to make it look for only a specific group of words, such as all words starting with TAR or IDIP, which are the beginning of document identifiers?
I am a subscriber and your Excel and Word letters are very helpful.
2018-11-25 23:25:38
thomas
Thank you for creating this Macro.
Unfortunately, I'm unable to get this to do it's thing... I'm confident that I created and ran the Macro correctly, but the end result is a new blank window that has a message at the top window bar that states, Not Responding...
I waited a good 5 minutes with no results.
I would be grateful if you could assist.
I'm running the latest version of Microsoft WORD on Windows 10.
Thanks!
2018-07-27 01:08:11
Tim
Thanks for the great solution above.
I need to generate a table at the end of a document which lists occurrences of specific words in the text. This list is predetermined, I do not need to input it every time I use the macro.
Is this possible? How can I adjust the macro above to achieve this?
2018-03-05 21:37:58
matthew
Sorry for the probably ignorant question, but how exactly do I input this macro into word once I've clicked "record macro." Do I need to type it all in? Is there a different menu I open to input it? I've found a couple instructional things about inputting macros, but none of the examples used anything like this. Any guidance would be much appreciated. Thank you
2017-12-10 05:22:10
Shahriyar
@James Thomas
This page includes good information on how to use Macros' code work into MS Word.
http://www.gmayor.com/installing_macro.htm
2017-12-10 05:19:04
Shahriyar
Thanks man! I used longer code to auto find duplicates, your solution is irreplaceable!! Keep up good work +
2017-10-28 12:03:31
Patricia Boyd
Thanks for this info. Another nonmacro way is to press Ctrl + F to open the Find box. Then type in the word you want to find. Then click on the "Find in" dropdown menu, and pick "main document." (Or, press Alt+i, m) This will tell you the number of occurrences of the word. (('d hesitate to use the "Replace" method you describe, because I'm usually editing for a client, and I don't want to show the replacement of the word with itself either as a tracked change or a non-tracked changed. If I turn track changes off, I run the risk of hiding the fact that I inserted a term as a track change. If I turn track changes on, then every single occurrence is going to show up as a tracked insertion of the same word.
2017-10-28 06:07:41
Ian
Thank you for these wonderful tips!
2017-10-28 05:16:16
James Thomas
That Macro looks amazing. And scary. Do you have Tips page that tells us how to get this Macro into our MS Word programs? Thanks - text stats are quite important to me and I had no idea they could be done within Word. Many thanks.
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.
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