AuthorsDen.com   Join | Login    
Where Authors and Readers come together!

SIGNED BOOKS    AUTHORS    BOOKS    SAMPLE CHAPTERS    AUDIOBOOKS    eBOOKS    STORIES    ARTICLES    POETRY    BLOGS    NEWS    VIDEOS    SUCCESS    TESTIMONIALS

Featured Authors:  M. R. Mathias, iSusan Smith, iJohn Henning, iEva Pasco, iFrank Whyte, iGibbs Williams, iShannon MacLeod, iRoxanne Howe-Murphy, iTeresa Walker, iKalikiano Kalei, i

  Home > Publishing > Articles > Help For Word Frequency Macro

Popular Publishing Articles
  1. Writing Advice From William Faulkner
  2. Suggestion for Amazon KDP Look Inside
  3. LA Times Festival of Books 2018
  4. Writing Advice From Maya Angelou
  5. Mining The Past For Hope and Motivatio
  6. How To Be Productive
  7. The Paranormal Suspense Game: An Inter
  8. Creating Suspense
  9. Writing Advice From Mark Twain
  10. Writing Advice From F. Scott Fitzgeral
  11. Writing And Life Advice From Somerset
  12. Transmedia Story-Telling (in a Hologra
  13. Writing and Life Quotes From Gene Rodd
  14. Writing Advice From Ray Bradbury
  15. I Have The Really Great Idea for a Boo
  16. Writing Advice From Henry Miller
  17. West Publishing, St Paul, Canadian Own
  18. Three Reasons Why Writers Must Get to
  19. The art of writing well
  20. Writing Advice From Ayn Rand
  21. Published Book
  22. Text and Meaning in: Elemental the Pow
  23. Writing Advice From John Steinbeck
  24. Interview with Mystic East Publishing
  25. Writing Advice From Michael Crichton
  26. Writing Advice From Edgar Allen Poe 2
  27. JUST DO IT!
  28. 21st Century Digital Authors on the Ri
  29. Tattoos
  30. Rejection--The Good, The Bad, and the
  31. Indy Writer survey- loaded with inform
  32. Writing for YA's and E-Publishing
  33. 5 Things a Professional Manuscript Edi
  34. Writing Advice From Edgar Allen Poe
  35. Sitcom
  36. Writing Advice From La Belle Rouge
  37. Publish America? I Think Not...
  38. Writing Advice From Mark Twain 2
  39. Submitting My Trash
  40. Miami Press—A SE Asian Financial Syndi
  41. American Public School Teachers rank 3
  42. Writing Advice From Anton Chekov
  43. Writing Advice On Weird Fiction From H
  44. Oprah vs Frey = Egg On Face
  45. Writing Advice From Kurt Vonnegut
  46. Writing Advice From The Writings Of Ch
  47. Writing Advice From Nora Roberts
  48. Starting an e-book Internet Publishing
  49. Is an E-Book a Real Book?
  50. Writing Tips From Ernest Hemmingway
  51. Writing and life quotes, Jules Verne
  52. The Revolt of the Poor - The Demise of
  53. Writing Quotes From Charles Bukowski
  54. Writing Fiction for Dummies -- Book Re
  55. Writing Advice From Dr. Seuss
  56. Writing Tips From JK Rowlings
  57. Writing Advice From Ernest Hemingway 2
  58. Cynth'ya Seeks Brains
  59. Options and Consequences in Modern Pub
  60. The Homeless, Psalm 85:10
  61. Authors and Books to Watch in 2009

Top 61 Publishing Articles:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,

Help For Word Frequency Macro
by John Patrick Lamont

Share   Save   Follow Me

Here's some additional instruction for those having some trouble with the MS Word - Word Frequency Macro.

There apparently is some confusion concerning the procedure for using the Word Frequency marco.  To help get it working for you, I've listed the way I use for patching macros into MS Word.

Also, of anyone has tried to contact me through my web sites, they are not lost. I'm in the process of designing and building them.  I would have liked to pay someone else to do it like many people do, but I can't afford it right now.  Self-publishing tends to be a bit expensive.  I'm sorry for any inconvenience or frustration the macro might or my web sites might have caused anyone.  I hope to have them up and running soon.
 
Try this procedure for using this macro.  I have tested it and it works fine with Word 2000.  If you have a different version of Word, you may have to adjust the procedure to work with your version.
 
1. Open the Macro box.  That's "Tools>Marco>Macros."

2. When the Macros window pops up, clear the window for "Macro Name:" and enter what you want to call the macro.  I called it, "WordFrequency1"

3. Click "Create."  This will create a blank macro.

4. Click on "WordFrequency1" then "Edit."  The "MicroSoft Visual Basic - Normal" editor will pop up.

5. Under "' WordFrequency1 Marco" (if that's what you called it,) and your name, paste the entire macro program from "Const maxwords = 20000" including "" different words ", vbOKOnly, "Finished")" to the end just before "End Sub."

6. In the "MicroSoft Visual Basic - Normal File" menu, click "Close and Return to MicroSoft Word."

7. Return to the Macro window, highlight the "WordFrequency1" macro and click "Run."  It will open a new Word document, count the words for you and list the totals.  Keep in mind that you must have a document with words loaded into Word so it will have something to count.  If you still have errors, please consult your Word manual.  You may not be entering the program properly.
 
Good luck and please let me know how it worked out for you.  If you still have errors, please be specific what the kind of error it is.  The errors are shown in red in the "MicroSoft Visual Basic - Normal" editor.
 
Sincerely,
John Patrick Lamont
 
Here's a copy for reference directly from my Word macros:
 
Sub WordFrequency1()
'
' WordFrequency1 Macro
    Const maxwords = 20000         '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            '
 
    ' 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
 


Click here to post or read comments.