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

J

Jan Kronsell

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
 
G

Greg Maxey

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top