Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub ConcordanceBuilder()
Application.ScreenUpdating = False
Dim StrIn As String, StrOut As String, StrTmp As String, StrExcl As String
Dim i As Long, j As Long, k As Long, Rng As Range
StrExcl = " a,the,and,or,but,not,to,of,i,you,we,he,her,them,she,him,it,they,who"
With ActiveDocument
StrIn = .Content.Text
For i = 1 To 255
Select Case i
Case 1 To 64, 91 To 96, 123 To 191, 247
StrIn = Replace(StrIn, Chr(i), " ")
End Select
Next
StrIn = " " & LCase(Trim(StrIn)) & " "
For i = 0 To UBound(Split(StrExcl, ","))
StrIn = Replace(StrIn, " " & Split(StrExcl, ",")(i) & " ", " ")
Next
While InStr(StrIn, " ") > 0
StrIn = Replace(StrIn, " ", " ")
Wend
StrIn = " " & Trim(StrIn) & " "
j = UBound(Split(StrIn, " "))
For i = 1 To j
If Len(Trim(StrIn)) = 0 Then Exit For
StrTmp = Split(StrIn, " ")(1)
While InStr(StrIn, " " & StrTmp & " ") > 0
StrIn = Replace(StrIn, " " & StrTmp & " ", " ")
Wend
k = j - UBound(Split(StrIn, " "))
StrOut = StrOut & StrTmp & vbTab & k & vbCr
j = UBound(Split(StrIn, " "))
Next
Set Rng = .Range.Characters.Last
With Rng
.InsertAfter Chr(12) & StrOut
.Start = .Start + 1
.ConvertToTable Separator:=vbTab, Numcolumns:=2
.Tables(1).Sort Excludeheader:=False, FieldNumber:=1, _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending, CaseSensitive:=False
End With
End With
Application.ScreenUpdating = True
End Sub
that's counts the s
can't counts the t
I'm counts the m
Sub ConcordanceBuilder()
Application.ScreenUpdating = False
Dim StrIn As String, StrOut As String, StrTmp As String, StrExcl As String
Dim i As Long, j As Long, k As Long, Rng As Range
'Words to be excluded
StrExcl = " a,the,and,or,but,not,to,of,i,you,we,he,her,them,she,him,it,they,who"
With ActiveDocument
'Load the content into a string
StrIn = .Content.Text
'Convert certain characters to spaces
For i = 1 To 255
Select Case i
Case 1 To 64, 91 To 96, 123 To 191, 247
StrIn = Replace(StrIn, Chr(i), " ")
End Select
Next
'Prefix the string with single spaces
StrIn = " " & LCase(Trim(StrIn)) & " "
'Convert excluded words to spaces
For i = 0 To UBound(Split(StrExcl, ","))
StrIn = Replace(StrIn, " " & Split(StrExcl, ",")(i) & " ", " ")
Next
'Convert all double spaces to single spaces
While InStr(StrIn, " ") > 0
StrIn = Replace(StrIn, " ", " ")
Wend
'Prefix the string with single spaces
StrIn = " " & Trim(StrIn) & " "
j = UBound(Split(StrIn, " "))
'Find each word in the string and replace all occurrences of that word with spaces
For i = 1 To j
If Len(Trim(StrIn)) = 0 Then Exit For
StrTmp = Split(StrIn, " ")(1)
While InStr(StrIn, " " & StrTmp & " ") > 0
StrIn = Replace(StrIn, " " & StrTmp & " ", " ")
Wend
'Re-calculate the array size.
'The difference in elements reflects how many words were replaced
k = j - UBound(Split(StrIn, " "))
'Output the word and its count, separated by a tab.
'Each word & count goes on a new line
StrOut = StrOut & StrTmp & vbTab & k & vbCr
'Re-set the array size.
j = UBound(Split(StrIn, " "))
Next
'Point to the end of the document
Set Rng = .Range.Characters.Last
With Rng
'Insert a page break, followed by the output string
.InsertAfter Chr(12) & StrOut
'Point to the first output character. The end looks after itself
.Start = .Start + 1
'Convert the output string to a table
.ConvertToTable Separator:=vbTab, Numcolumns:=2
'Sort the table
.Tables(1).Sort Excludeheader:=False, FieldNumber:=1, _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending, CaseSensitive:=False
End With
End With
Application.ScreenUpdating = True
End Sub