Using VBA, to count the number of characters in the active document do:
ActiveDocument.Range.ComputeStatistics(wdStatisticCharacters)
or
Activedocument.Range.Characters.Count
To get the count for the current selection:
Selection.Range.ComputeStatistics(wdStatisticCharacters)
or
Selection.Range.Characters.Count
The second method in each example counts spaces as characters, the first doesn't.
EDIT: I did some speed testing on various methods to count the instances of a char in a document. Regular expressions and stuffing the document contents into a string are fastest - many times faster than looping through each character or FIND
For my test document I copied the contents of this web page into a Word document. As an accuracy check, I used Word's Find
function/panel to find the number of instances of lower case "a". Before I edited this answer that was 409 instances.
I then created four functions to count the number of instances of a character (any string actually) in a Word document. The first simply loops through each character in the doc, similar to Andrew's. The second uses the Find
function. The third stuffs the contents of the document into a string and loops through it. The fourth does the same thing but check the matches using a regular expression:
Function GetCharCountLoop(doc As Word.Document, char As String) As Long
Dim i As Long
Dim CharCount As Long
With doc.Content.Characters
For i = 1 To .Count
If .Item(i) = char Then
CharCount = CharCount + 1
End If
Next i
End With
GetCharCountLoop = CharCount
End Function
Function GetCharCountFind(doc As Word.Document, char As String) As Long
Dim i As Long
Dim CharCount As Long
With doc.Content.Find
Do While .Execute(FindText:=char, Forward:=True, MatchWholeWord:=False, MatchCase:=True) = True
CharCount = CharCount + 1
Loop
GetCharCountFind = CharCount
End With
End Function
Function GetCharCountString(doc As Word.Document, char As String) As Long
Dim chars As String
Dim i As Long
Dim CharCount As Long
chars = doc.Content
For i = 1 To Len(chars)
If Mid$(chars, i, 1) = char Then
CharCount = CharCount + 1
End If
Next i
GetCharCountString = CharCount
End Function
Function GetCharCountRegex(doc As Word.Document, char As String) As Long
Dim chars As String
Dim CharCount As Long
Dim objRegExp As Object
chars = doc.Content
Set objRegExp = CreateObject("VBScript.RegExp")
With objRegExp
.Pattern = char
.IgnoreCase = False
.Global = True
CharCount = .Execute(chars).Count
End With
GetCharCountRegex = CharCount
End Function
I then tested them using this sub, running a single loop:
Sub TimeMethods()
Dim char As String
Dim CharCount As Long
Dim LoopCounter As Long
Dim NumLoops As Long
Dim StartTime As Double
char = "a"
NumLoops = 1
StartTime = Timer
For LoopCounter = 1 To NumLoops
CharCount = GetCharCountLoop(ActiveDocument, char)
Next LoopCounter
Debug.Print CharCount
Debug.Print Timer - StartTime
StartTime = Timer
For LoopCounter = 1 To NumLoops
CharCount = GetCharCountFind(ActiveDocument, char)
Next LoopCounter
Debug.Print CharCount
Debug.Print Timer - StartTime
StartTime = Timer
For LoopCounter = 1 To NumLoops
CharCount = GetCharCountString(ActiveDocument, char)
Next LoopCounter
Debug.Print CharCount
Debug.Print Timer - StartTime
StartTime = Timer
For LoopCounter = 1 To NumLoops
CharCount = GetCharCountRegex(ActiveDocument, char)
Next LoopCounter
Debug.Print CharCount
Debug.Print Timer - StartTime
End Sub
The results are dramatic:
GetCharCountLoop - 514.3046875 seconds
GetCharCountFind - 0.5859375 seconds
GetCharCountString - 0.015625 seconds
GetCharCountRegex - 0.015625 seconds
I dropped GetCharCountLoop from the running and ran the other three 100 times. According to this rudimentary timing, stuffing the contents into a string and counting, or using a regular expression, are almost 50 times faster than the Find method:
GetCharCountFind - 30.984375 seconds
GetCharCountString - 0.6328125 seconds
GetCharCountRegex - 0.578125 seconds
Note that the slowness of the first method, looping through each character is most evident with longer docs. In my initial testing - a file with just a few words - it was only twice as slow as the Find method.
Also note that I originally turned off ScreenUpdating
per Andrew's subroutine, but it seems that makes no difference.