character count

A

Annette

is there a way to count individual characters in word or
is there an attachment available?
I am creating a name directory and need to buy the
individual letters to create each name. I don't want to go
through the 30 odd names: counting all the A's, B's etc.
Could you help me?
Thank you.

CAR
 
J

Jay Freedman

Hi, Annette,

Use this macro. (For instructions on putting a macro into a template, see
http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm.)

Sub CountChars()
Dim Letters(25) As Long
Dim startCt As Long, endCt As Long
Dim oRg As Range
Dim ch As Integer
Dim msg As String

For ch = 1 To 26
Set oRg = ActiveDocument.Range
startCt = oRg.Characters.Count

With oRg.Find
.ClearFormatting
.Format = False
.Forward = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.Text = Chr(64 + ch) ' "A" = Chr(65)
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With

endCt = oRg.Characters.Count
Letters(ch - 1) = startCt - endCt
ActiveDocument.Undo
Next ch

For ch = 1 To 26
msg = msg & Chr(64 + ch) & vbTab & _
Letters(ch - 1) & vbCr
Next ch
MsgBox msg, , "Results"
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