How can I count numbers of specific letter in a document?

  • Thread starter Thread starter andy
  • Start date Start date
There may be an easier way, but this is what I do. I count the number of
letters in the document. Then i search and replace for instance "t" with
nothing. Then counts the letters again. The difference between the two
numbers, are the number of t's. Then I do the same for the other letters.

Jan
 
Andy

You can use this macro:

Sub CountOccurrences()



Dim iCount As Long

Dim strSearch As String



strSearch = InputBox$("Type in the character-word-or phrase that you want to
find and count.")

iCount = 0



With ActiveDocument.Content.Find

.Text = strSearch

.Format = False

.Wrap = wdFindStop

Do While .Execute

iCount = iCount + 1

Loop

End With



If iCount = 1 Then

MsgBox Chr$(34) & strSearch & Chr$(34) & " was found " & _

iCount & " time."

End If

If iCount > 1 Then

MsgBox Chr$(34) & strSearch & Chr$(34) & " was found " & _

iCount & " times."

End If

End Sub
 
Back
Top