Counting number of characters in selected text

P

Proboscis

Sometimes I need to know exactly how many characters are in a certain
sentence or group of sentences. I was thinking the easiest way would be to
select the text and have Word count and display the number of characters.

Anyone any idea how to do this? Is the an existing add-on to do the job?
 
G

Gregory K. Maxey

That will work provided you will agree with Word's definition of a
character.

Sub ScratchMacro()
MsgBox Selection.Characters.Count
End Sub
 
G

Gregory K. Maxey

Otherwise you would need to evaluate each individual character. For
example, this procedure ignores spaces, periods, exclamation points, and
question marks:

Sub ScratchMacroII()
Dim i As Long
Dim lngCnt As Long
For i = 1 To Selection.Characters.Count
If Not Mid(Selection, i, 1) Like "[ .?!]" Then
lngCnt = lngCnt + 1
End If
Next
MsgBox lngCnt
End Sub
 
P

Proboscis

Gregory K. Maxey said:
Otherwise you would need to evaluate each individual character. For
example, this procedure ignores spaces, periods, exclamation points, and
question marks:

Sub ScratchMacroII()
Dim i As Long
Dim lngCnt As Long
For i = 1 To Selection.Characters.Count
If Not Mid(Selection, i, 1) Like "[ .?!]" Then
lngCnt = lngCnt + 1
End If
Next
MsgBox lngCnt
End Sub

Sometimes I need to know exactly how many characters are in a certain
sentence or group of sentences. I was thinking the easiest way would
be to select the text and have Word count and display the number of
characters.
Anyone any idea how to do this? Is the an existing add-on to do the
job?

Thanks Greg,

For my purpose, spaces and punctuation also count. I suppose you first
version would do, then.
 
P

Proboscis

Gregory K. Maxey said:
.
That will work provided you will agree with Word's definition of a
character.

Sub ScratchMacro()
MsgBox Selection.Characters.Count
End Sub

Just discovered this can be done with the toolbar Word Count in Word 2003.
 

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