" different words ", vbOKOnly, "Finished") J = MsgBox("There were " & Trim(Str(WordNum)) & _
TmpName = ĭocuments.Add Template:=tmpName, NewTemplate:=False If (Not ByFreq And Words(l) Freq(k)) Then k = l StatusBar = "Remaining: " & ttlwds & ", Unique: " & WordNum The following VBA macro will do just that.Ĭonst maxwords = 9000 'Maximum unique words allowedĭim SingleWord As String 'Raw word pulled from docĭim Words(maxwords) As String 'Array to hold unique wordsĭim Freq(maxwords) As Integer 'Frequency counter for unique wordsĭim WordNum As Integer 'Number of unique wordsĭim ByFreq As Boolean 'Flag for sorting orderĭim ttlwds As Long 'Total words in the documentĭim Excludes As String 'Words to be excludedĭim j, k, l, Temp As Integer 'Temporary variablesĭim ans As String 'How user wants to sort resultsĮxcludes = ""Īns = InputBox("Sort by WORD or by FREQ?", "Sort order", "WORD") 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. MsgBox sResponse & " appears " & iCount & " times" Prompt:="What word do you want to count?", _ ' Input different words until the user clicks cancel It will continue to ask for another word until the user clicks on the Cancel button. The following macro prompts the user for a word, and then counts the number of times that word appears in the document. You can automate the process a bit by using a macro to search through the document and count for you. This approach works great if you just have one or two words or phrases you want to know about. Word makes the replacements and shows you how many instances it replaced.
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.