E
eugene
Hi,
Does anyone know how to count special characters within a range?
A macro that includes ActiveDocument.Words.count gives a different result
for count than Word's word count toolbar. The latter produces the right
result. The macro seems to be including the "paragraph mark" and other items
such as "*" "%" etc. as separate words even though I have them directly
adjacent to words.
I would like to make the count more precise and thus would like to subtract
the number of times these special characters appear in the document and
range.
I can count these special characters in the entire document by looping
through ActiveDocument.Characters and selecting those that have ascii values
equal to, less than or greater than certain values (see code after my
signature). But I don't know how to do this within a range and a macro I am
working on needs to have that ability.
Any help would be appreciated. It will probably be enough to just give me
the equivalent of ActiveDocument.Characters for a loop through a range.
--
eugene
PS Can anyone influence Microsoft to fix this. It is quite odd for there to
be such a difference and is quite disturbing that the macro can't do it right.
CODE
Doug Robbins response to "Count Uppercase alphabets" posted 1/3/07
Dim i As Long, achar As Range
i = 0
For Each achar In ActiveDocument.Characters
If Asc(achar) > 64 Then
If Asc(achar) < 91 Then
i = i + 1
End If
End If
Next achar
MsgBox i
Does anyone know how to count special characters within a range?
A macro that includes ActiveDocument.Words.count gives a different result
for count than Word's word count toolbar. The latter produces the right
result. The macro seems to be including the "paragraph mark" and other items
such as "*" "%" etc. as separate words even though I have them directly
adjacent to words.
I would like to make the count more precise and thus would like to subtract
the number of times these special characters appear in the document and
range.
I can count these special characters in the entire document by looping
through ActiveDocument.Characters and selecting those that have ascii values
equal to, less than or greater than certain values (see code after my
signature). But I don't know how to do this within a range and a macro I am
working on needs to have that ability.
Any help would be appreciated. It will probably be enough to just give me
the equivalent of ActiveDocument.Characters for a loop through a range.
--
eugene
PS Can anyone influence Microsoft to fix this. It is quite odd for there to
be such a difference and is quite disturbing that the macro can't do it right.
CODE
Doug Robbins response to "Count Uppercase alphabets" posted 1/3/07
Dim i As Long, achar As Range
i = 0
For Each achar In ActiveDocument.Characters
If Asc(achar) > 64 Then
If Asc(achar) < 91 Then
i = i + 1
End If
End If
Next achar
MsgBox i