#1   Report Post  
Anthea
 
Posts: n/a
Default Word frequencies

Hello,

I have been told that somewhere in Word there is a way to check how
frequently a word occurs in the English language. I'm trying to determine
word frequencies for a large list of words and if I have the option of doing
it within the Word program, that would be heaps quicker.

Hope someone can help me....Thanks!
  #2   Report Post  
Greg Maxey
 
Posts: n/a
Default

The following macro does a decent job.



Sub WordFrequency()



Dim SingleWord As String 'Raw word pulled from doc

Const maxwords = 9000 'Maximum unique words allowed

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 IngWordCount As Long 'Total non-excluded words in document

Dim NonWordObjects As Long

Dim AllWordOjects As Long

Dim TotalWords As Long

Dim tword As String '



'Set up excluded words

'Excludes = "[pickleloaf][gruntbutter]"

'Excludes = Excludes & InputBox$("The following words are excluded by
default: " & Excludes & ". Enter additional words that you wish to exclude,
surrounding each word with [ ].", "Excluded Words", "")

Excludes = InputBox$("Enter words that you wish to exclude. Place each word
within square brackets [ ]. Example: [is][a].", "Excluded Words", "")



'Find out how to sort

ByFreq = True

Ans = InputBox$("Default sort order is word freqeuncy. To sort
alphabetically by word, type Word in the field below.", "Sort order",
"FREQ")

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

'AllWordObjects = ActiveDocument.Words.Count

'TotalWords = NonWordObjects



'Control the repeat

For Each aword In ActiveDocument.Words

SingleWord = Trim(LCase(aword))

If SingleWord "a" Or SingleWord "z" Then SingleWord = "" 'Out of range?

If SingleWord "a" Or SingleWord "z" Then NonWordObjects = NonWordObjects
+ 1

'SingleWord = Trim(aword)

'If SingleWord "A" Or SingleWord "z" Then SingleWord = "" 'Out of range?

If InStr(Excludes, "[" & SingleWord & "]") Then SingleWord = "" 'On exclude
list?

If Len(SingleWord) 0 Then

IngWordCount = IngWordCount + 1

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("The maximum array size has been exceeded. Increase
maxwords.", 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



AllWordObjects = ActiveDocument.Words.Count

NonWordObjects = NonWordObjects

TotalWords = AllWordObjects - NonWordObjects



'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:=Words(j) & vbTab & Trim(Str(Freq(j))) & vbCrLf

Next j

End With

ActiveDocument.Range.Select

Selection.ConvertToTable

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows.Add BeforeRow:=Selection.Rows(1)

ActiveDocument.Tables(1).Cell(1, 1).Range.InsertBefore "Unique Words"

ActiveDocument.Tables(1).Cell(1, 2).Range.InsertBefore "Number of
Occurrences"

ActiveDocument.Tables(1).Columns(2).Select

Selection.ParagraphFormat.Alignment = wdAlignParagraphRight

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows(1).Shading.Backgroun dPatternColor =
wdColorGray20

ActiveDocument.Tables(1).Columns(1).PreferredWidth = InchesToPoints(4.75)

ActiveDocument.Tables(1).Columns(2).PreferredWidth = InchesToPoints(1.9)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Summary"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore "Total"

ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.BackgroundPatternColor
= wdColorGray20





ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Unique Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore Trim(Str(WordNum))

ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.BackgroundPatternColor
= wdColorAutomatic



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Non-Excluded Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (IngWordCount)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Words (Excluded and Non-Excluded) in
Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (TotalWords)

System.Cursor = wdCursorNormal



MsgBox "This document contains " & Trim(Str(WordNum)) & " unique words. "

MsgBox "This document contains " & IngWordCount & " non-excluded words. "

MsgBox "This document contains a total of " & TotalWords & " (excluded and
non-excluded) words. "

MsgBox "For more statistics on this document, use ToolsWord Count in the
original document. "



Selection.HomeKey wdStory



End Sub



--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Anthea wrote:
Hello,

I have been told that somewhere in Word there is a way to check how
frequently a word occurs in the English language. I'm trying to
determine word frequencies for a large list of words and if I have
the option of doing it within the Word program, that would be heaps
quicker.

Hope someone can help me....Thanks!



  #3   Report Post  
Anthea
 
Posts: n/a
Default

Thanks for the quick reply, Greg, but I'm not sure how to use what you've
posted!? Is it within Word, or is it a separate program?
Sorry, I'm a little slow when it comes to some of the more technical stuff...

Anthea

"Greg Maxey" wrote:

The following macro does a decent job.



Sub WordFrequency()



Dim SingleWord As String 'Raw word pulled from doc

Const maxwords = 9000 'Maximum unique words allowed

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 IngWordCount As Long 'Total non-excluded words in document

Dim NonWordObjects As Long

Dim AllWordOjects As Long

Dim TotalWords As Long

Dim tword As String '



'Set up excluded words

'Excludes = "[pickleloaf][gruntbutter]"

'Excludes = Excludes & InputBox$("The following words are excluded by
default: " & Excludes & ". Enter additional words that you wish to exclude,
surrounding each word with [ ].", "Excluded Words", "")

Excludes = InputBox$("Enter words that you wish to exclude. Place each word
within square brackets [ ]. Example: [is][a].", "Excluded Words", "")



'Find out how to sort

ByFreq = True

Ans = InputBox$("Default sort order is word freqeuncy. To sort
alphabetically by word, type Word in the field below.", "Sort order",
"FREQ")

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

'AllWordObjects = ActiveDocument.Words.Count

'TotalWords = NonWordObjects



'Control the repeat

For Each aword In ActiveDocument.Words

SingleWord = Trim(LCase(aword))

If SingleWord "a" Or SingleWord "z" Then SingleWord = "" 'Out of range?

If SingleWord "a" Or SingleWord "z" Then NonWordObjects = NonWordObjects
+ 1

'SingleWord = Trim(aword)

'If SingleWord "A" Or SingleWord "z" Then SingleWord = "" 'Out of range?

If InStr(Excludes, "[" & SingleWord & "]") Then SingleWord = "" 'On exclude
list?

If Len(SingleWord) 0 Then

IngWordCount = IngWordCount + 1

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("The maximum array size has been exceeded. Increase
maxwords.", 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



AllWordObjects = ActiveDocument.Words.Count

NonWordObjects = NonWordObjects

TotalWords = AllWordObjects - NonWordObjects



'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:=Words(j) & vbTab & Trim(Str(Freq(j))) & vbCrLf

Next j

End With

ActiveDocument.Range.Select

Selection.ConvertToTable

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows.Add BeforeRow:=Selection.Rows(1)

ActiveDocument.Tables(1).Cell(1, 1).Range.InsertBefore "Unique Words"

ActiveDocument.Tables(1).Cell(1, 2).Range.InsertBefore "Number of
Occurrences"

ActiveDocument.Tables(1).Columns(2).Select

Selection.ParagraphFormat.Alignment = wdAlignParagraphRight

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows(1).Shading.Backgroun dPatternColor =
wdColorGray20

ActiveDocument.Tables(1).Columns(1).PreferredWidth = InchesToPoints(4.75)

ActiveDocument.Tables(1).Columns(2).PreferredWidth = InchesToPoints(1.9)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Summary"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore "Total"

ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.BackgroundPatternColor
= wdColorGray20





ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Unique Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore Trim(Str(WordNum))

ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.BackgroundPatternColor
= wdColorAutomatic



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Non-Excluded Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (IngWordCount)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Words (Excluded and Non-Excluded) in
Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (TotalWords)

System.Cursor = wdCursorNormal



MsgBox "This document contains " & Trim(Str(WordNum)) & " unique words. "

MsgBox "This document contains " & IngWordCount & " non-excluded words. "

MsgBox "This document contains a total of " & TotalWords & " (excluded and
non-excluded) words. "

MsgBox "For more statistics on this document, use ToolsWord Count in the
original document. "



Selection.HomeKey wdStory



End Sub



--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Anthea wrote:
Hello,

I have been told that somewhere in Word there is a way to check how
frequently a word occurs in the English language. I'm trying to
determine word frequencies for a large list of words and if I have
the option of doing it within the Word program, that would be heaps
quicker.

Hope someone can help me....Thanks!




  #4   Report Post  
Greg Maxey
 
Posts: n/a
Default

Anthea,

It is a macro that runs in Word. You have to install it and then run it.
It will look at your document and count the occurrence of each unique word
then build a report.

For help installing a macro see: http://www.gmayor.com/installing_macro.htm

Do to the word wrapping that has undoubtably occurred, you will probably
have to clean up the code when you paste in the the VB Editor.

Another easy method to count occurrences of individual words is to use
EditReplace. Type the word in the find field and ^& in the replace field
then replace all. ^& represents the contents of the find field so your
document won't be changed at all. Word will report how many replacements
were made which is the same a word count.


--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Anthea wrote:
Thanks for the quick reply, Greg, but I'm not sure how to use what
you've
posted!? Is it within Word, or is it a separate program?
Sorry, I'm a little slow when it comes to some of the more technical
stuff...

Anthea

"Greg Maxey" wrote:

The following macro does a decent job.






--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Anthea wrote:
Hello,

I have been told that somewhere in Word there is a way to check how
frequently a word occurs in the English language. I'm trying to
determine word frequencies for a large list of words and if I have
the option of doing it within the Word program, that would be heaps
quicker.

Hope someone can help me....Thanks!



  #5   Report Post  
Jezebel
 
Posts: n/a
Default

If you'd rather not use a macro, copy your word list to Excel (simple copy
and paste will do) then use Excel's statistics functions or create a pivot
table.



"Anthea" wrote in message
...
Thanks for the quick reply, Greg, but I'm not sure how to use what you've
posted!? Is it within Word, or is it a separate program?
Sorry, I'm a little slow when it comes to some of the more technical

stuff...

Anthea

"Greg Maxey" wrote:

The following macro does a decent job.



Sub WordFrequency()



Dim SingleWord As String 'Raw word pulled from doc

Const maxwords = 9000 'Maximum unique words allowed

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 IngWordCount As Long 'Total non-excluded words in document

Dim NonWordObjects As Long

Dim AllWordOjects As Long

Dim TotalWords As Long

Dim tword As String '



'Set up excluded words

'Excludes = "[pickleloaf][gruntbutter]"

'Excludes = Excludes & InputBox$("The following words are excluded by
default: " & Excludes & ". Enter additional words that you wish to

exclude,
surrounding each word with [ ].", "Excluded Words", "")

Excludes = InputBox$("Enter words that you wish to exclude. Place each

word
within square brackets [ ]. Example: [is][a].", "Excluded Words", "")



'Find out how to sort

ByFreq = True

Ans = InputBox$("Default sort order is word freqeuncy. To sort
alphabetically by word, type Word in the field below.", "Sort order",
"FREQ")

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

'AllWordObjects = ActiveDocument.Words.Count

'TotalWords = NonWordObjects



'Control the repeat

For Each aword In ActiveDocument.Words

SingleWord = Trim(LCase(aword))

If SingleWord "a" Or SingleWord "z" Then SingleWord = "" 'Out of

range?

If SingleWord "a" Or SingleWord "z" Then NonWordObjects =

NonWordObjects
+ 1

'SingleWord = Trim(aword)

'If SingleWord "A" Or SingleWord "z" Then SingleWord = "" 'Out of

range?

If InStr(Excludes, "[" & SingleWord & "]") Then SingleWord = "" 'On

exclude
list?

If Len(SingleWord) 0 Then

IngWordCount = IngWordCount + 1

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("The maximum array size has been exceeded. Increase
maxwords.", 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



AllWordObjects = ActiveDocument.Words.Count

NonWordObjects = NonWordObjects

TotalWords = AllWordObjects - NonWordObjects



'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:=Words(j) & vbTab & Trim(Str(Freq(j))) & vbCrLf

Next j

End With

ActiveDocument.Range.Select

Selection.ConvertToTable

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows.Add BeforeRow:=Selection.Rows(1)

ActiveDocument.Tables(1).Cell(1, 1).Range.InsertBefore "Unique Words"

ActiveDocument.Tables(1).Cell(1, 2).Range.InsertBefore "Number of
Occurrences"

ActiveDocument.Tables(1).Columns(2).Select

Selection.ParagraphFormat.Alignment = wdAlignParagraphRight

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows(1).Shading.Backgroun dPatternColor =
wdColorGray20

ActiveDocument.Tables(1).Columns(1).PreferredWidth =

InchesToPoints(4.75)

ActiveDocument.Tables(1).Columns(2).PreferredWidth = InchesToPoints(1.9)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Summary"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore "Total"


ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.B
ackgroundPatternColor
= wdColorGray20





ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Unique Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore Trim(Str(WordNum))


ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.B
ackgroundPatternColor
= wdColorAutomatic



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Non-Excluded Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (IngWordCount)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Words (Excluded and Non-Excluded) in
Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (TotalWords)

System.Cursor = wdCursorNormal



MsgBox "This document contains " & Trim(Str(WordNum)) & " unique words.

"

MsgBox "This document contains " & IngWordCount & " non-excluded words.

"

MsgBox "This document contains a total of " & TotalWords & " (excluded

and
non-excluded) words. "

MsgBox "For more statistics on this document, use ToolsWord Count in

the
original document. "



Selection.HomeKey wdStory



End Sub



--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Anthea wrote:
Hello,

I have been told that somewhere in Word there is a way to check how
frequently a word occurs in the English language. I'm trying to
determine word frequencies for a large list of words and if I have
the option of doing it within the Word program, that would be heaps
quicker.

Hope someone can help me....Thanks!








  #6   Report Post  
Anthea
 
Posts: n/a
Default

Thanks guys, you've both taught me something I didn't know

However, I'm trying to find the word frequency for the English language, not
just my document...you know, how often we use it in conversation/written word
etc. It's just so much more difficult than I initially thought! I was
informed that Word had a function to help with this and that's what I'm
trying to clarify.

Thanks again!

"Jezebel" wrote:

If you'd rather not use a macro, copy your word list to Excel (simple copy
and paste will do) then use Excel's statistics functions or create a pivot
table.



"Anthea" wrote in message
...
Thanks for the quick reply, Greg, but I'm not sure how to use what you've
posted!? Is it within Word, or is it a separate program?
Sorry, I'm a little slow when it comes to some of the more technical

stuff...

Anthea

"Greg Maxey" wrote:

The following macro does a decent job.



Sub WordFrequency()



Dim SingleWord As String 'Raw word pulled from doc

Const maxwords = 9000 'Maximum unique words allowed

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 IngWordCount As Long 'Total non-excluded words in document

Dim NonWordObjects As Long

Dim AllWordOjects As Long

Dim TotalWords As Long

Dim tword As String '



'Set up excluded words

'Excludes = "[pickleloaf][gruntbutter]"

'Excludes = Excludes & InputBox$("The following words are excluded by
default: " & Excludes & ". Enter additional words that you wish to

exclude,
surrounding each word with [ ].", "Excluded Words", "")

Excludes = InputBox$("Enter words that you wish to exclude. Place each

word
within square brackets [ ]. Example: [is][a].", "Excluded Words", "")



'Find out how to sort

ByFreq = True

Ans = InputBox$("Default sort order is word freqeuncy. To sort
alphabetically by word, type Word in the field below.", "Sort order",
"FREQ")

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

'AllWordObjects = ActiveDocument.Words.Count

'TotalWords = NonWordObjects



'Control the repeat

For Each aword In ActiveDocument.Words

SingleWord = Trim(LCase(aword))

If SingleWord "a" Or SingleWord "z" Then SingleWord = "" 'Out of

range?

If SingleWord "a" Or SingleWord "z" Then NonWordObjects =

NonWordObjects
+ 1

'SingleWord = Trim(aword)

'If SingleWord "A" Or SingleWord "z" Then SingleWord = "" 'Out of

range?

If InStr(Excludes, "[" & SingleWord & "]") Then SingleWord = "" 'On

exclude
list?

If Len(SingleWord) 0 Then

IngWordCount = IngWordCount + 1

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("The maximum array size has been exceeded. Increase
maxwords.", 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



AllWordObjects = ActiveDocument.Words.Count

NonWordObjects = NonWordObjects

TotalWords = AllWordObjects - NonWordObjects



'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:=Words(j) & vbTab & Trim(Str(Freq(j))) & vbCrLf

Next j

End With

ActiveDocument.Range.Select

Selection.ConvertToTable

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows.Add BeforeRow:=Selection.Rows(1)

ActiveDocument.Tables(1).Cell(1, 1).Range.InsertBefore "Unique Words"

ActiveDocument.Tables(1).Cell(1, 2).Range.InsertBefore "Number of
Occurrences"

ActiveDocument.Tables(1).Columns(2).Select

Selection.ParagraphFormat.Alignment = wdAlignParagraphRight

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows(1).Shading.Backgroun dPatternColor =
wdColorGray20

ActiveDocument.Tables(1).Columns(1).PreferredWidth =

InchesToPoints(4.75)

ActiveDocument.Tables(1).Columns(2).PreferredWidth = InchesToPoints(1.9)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Summary"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore "Total"


ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.B
ackgroundPatternColor
= wdColorGray20





ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Unique Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore Trim(Str(WordNum))


ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.B
ackgroundPatternColor
= wdColorAutomatic



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Non-Excluded Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (IngWordCount)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Words (Excluded and Non-Excluded) in
Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (TotalWords)

System.Cursor = wdCursorNormal



MsgBox "This document contains " & Trim(Str(WordNum)) & " unique words.

"

MsgBox "This document contains " & IngWordCount & " non-excluded words.

"

MsgBox "This document contains a total of " & TotalWords & " (excluded

and
non-excluded) words. "

MsgBox "For more statistics on this document, use ToolsWord Count in

the
original document. "



Selection.HomeKey wdStory



End Sub



--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Anthea wrote:
Hello,

I have been told that somewhere in Word there is a way to check how
frequently a word occurs in the English language. I'm trying to
determine word frequencies for a large list of words and if I have
the option of doing it within the Word program, that would be heaps
quicker.

Hope someone can help me....Thanks!






  #7   Report Post  
Jezebel
 
Posts: n/a
Default

No, Word has no built-in function for this. It would be feasible to write a
macro to track it, but the result would surely be very skewed on any one
computer? Claude Shannon did work on this, in relation to writers' styles
and word pair frequency.

Try: http://www.comp.lancs.ac.uk/ucrel/bncfreq/ -- this is a website devoted
to English language word frequencies.




"Anthea" wrote in message
...
Thanks guys, you've both taught me something I didn't know

However, I'm trying to find the word frequency for the English language,

not
just my document...you know, how often we use it in conversation/written

word
etc. It's just so much more difficult than I initially thought! I was
informed that Word had a function to help with this and that's what I'm
trying to clarify.

Thanks again!

"Jezebel" wrote:

If you'd rather not use a macro, copy your word list to Excel (simple

copy
and paste will do) then use Excel's statistics functions or create a

pivot
table.



"Anthea" wrote in message
...
Thanks for the quick reply, Greg, but I'm not sure how to use what

you've
posted!? Is it within Word, or is it a separate program?
Sorry, I'm a little slow when it comes to some of the more technical

stuff...

Anthea

"Greg Maxey" wrote:

The following macro does a decent job.



Sub WordFrequency()



Dim SingleWord As String 'Raw word pulled from doc

Const maxwords = 9000 'Maximum unique words allowed

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 IngWordCount As Long 'Total non-excluded words in

document

Dim NonWordObjects As Long

Dim AllWordOjects As Long

Dim TotalWords As Long

Dim tword As String '



'Set up excluded words

'Excludes = "[pickleloaf][gruntbutter]"

'Excludes = Excludes & InputBox$("The following words are excluded

by
default: " & Excludes & ". Enter additional words that you wish to

exclude,
surrounding each word with [ ].", "Excluded Words", "")

Excludes = InputBox$("Enter words that you wish to exclude. Place

each
word
within square brackets [ ]. Example: [is][a].", "Excluded Words",

"")



'Find out how to sort

ByFreq = True

Ans = InputBox$("Default sort order is word freqeuncy. To sort
alphabetically by word, type Word in the field below.", "Sort

order",
"FREQ")

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

'AllWordObjects = ActiveDocument.Words.Count

'TotalWords = NonWordObjects



'Control the repeat

For Each aword In ActiveDocument.Words

SingleWord = Trim(LCase(aword))

If SingleWord "a" Or SingleWord "z" Then SingleWord = "" 'Out of

range?

If SingleWord "a" Or SingleWord "z" Then NonWordObjects =

NonWordObjects
+ 1

'SingleWord = Trim(aword)

'If SingleWord "A" Or SingleWord "z" Then SingleWord = "" 'Out

of
range?

If InStr(Excludes, "[" & SingleWord & "]") Then SingleWord = "" 'On

exclude
list?

If Len(SingleWord) 0 Then

IngWordCount = IngWordCount + 1

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("The maximum array size has been exceeded. Increase
maxwords.", 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



AllWordObjects = ActiveDocument.Words.Count

NonWordObjects = NonWordObjects

TotalWords = AllWordObjects - NonWordObjects



'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:=Words(j) & vbTab & Trim(Str(Freq(j))) & vbCrLf

Next j

End With

ActiveDocument.Range.Select

Selection.ConvertToTable

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows.Add BeforeRow:=Selection.Rows(1)

ActiveDocument.Tables(1).Cell(1, 1).Range.InsertBefore "Unique

Words"

ActiveDocument.Tables(1).Cell(1, 2).Range.InsertBefore "Number of
Occurrences"

ActiveDocument.Tables(1).Columns(2).Select

Selection.ParagraphFormat.Alignment = wdAlignParagraphRight

Selection.Collapse wdCollapseStart

ActiveDocument.Tables(1).Rows(1).Shading.Backgroun dPatternColor =
wdColorGray20

ActiveDocument.Tables(1).Columns(1).PreferredWidth =

InchesToPoints(4.75)

ActiveDocument.Tables(1).Columns(2).PreferredWidth =

InchesToPoints(1.9)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Summary"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore "Total"



ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.B
ackgroundPatternColor
= wdColorGray20





ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Unique Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore Trim(Str(WordNum))



ActiveDocument.Tables(1).Rows(ActiveDocument.Table s(1).Rows.Count).Shading.B
ackgroundPatternColor
= wdColorAutomatic



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Non-Excluded Words in Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (IngWordCount)



ActiveDocument.Tables(1).Rows.Add

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.InsertBefore "Number of Words (Excluded and Non-Excluded)

in
Document"

ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
2).Range.InsertBefore (TotalWords)

System.Cursor = wdCursorNormal



MsgBox "This document contains " & Trim(Str(WordNum)) & " unique

words.
"

MsgBox "This document contains " & IngWordCount & " non-excluded

words.
"

MsgBox "This document contains a total of " & TotalWords & "

(excluded
and
non-excluded) words. "

MsgBox "For more statistics on this document, use ToolsWord Count

in
the
original document. "



Selection.HomeKey wdStory



End Sub



--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Anthea wrote:
Hello,

I have been told that somewhere in Word there is a way to check

how
frequently a word occurs in the English language. I'm trying to
determine word frequencies for a large list of words and if I have
the option of doing it within the Word program, that would be

heaps
quicker.

Hope someone can help me....Thanks!








Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I divide a page into three sections? Bonnie Microsoft Word Help 3 May 8th 23 02:47 AM
Continuous breaks convert to next page breaks Jennifer Hunt Microsoft Word Help 2 December 30th 04 06:45 PM
MS word suggest: Doc linking Krystian Microsoft Word Help 4 December 29th 04 05:41 AM
macro in word js Microsoft Word Help 1 December 28th 04 04:01 AM
saving the workspace Mike Microsoft Word Help 3 December 9th 04 12:32 AM


All times are GMT +1. The time now is 09:47 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"