character count

T

tushar

hi

the property App.Characters.Count seems to give the no of
chars + special chars like carraige return - i know how to
parse the document and remove those chars from the count -
but i was wondering if there was an easier way to
determine the no of chars with spaces - same as the menu
Tools/Word count returns.

The fn i use now is ( is there a better implmentation for
it?):
' counts chars and words in txt
' char are spaces but not special chars like carraige
return (chr13)
' params:1. txt As String - the text to count chars in
'Output: int of char count
Function cntChar(txt As String) As Integer
Dim i1 As Integer, i As Integer, d
wordCnt = 0


i1 = 0
' could have white space after white space so flag
'white space = char 13 or space
Dim inWord As Boolean
For i = 1 To Len(txt)
If (i Mod 250) = 0 Then Sheets(4).Range("b14").Value =
Sheets(4).Range("b14").Value & "."

d = Mid(txt, i, 1)

If (Asc(d) > 30) Then
i1 = i1 + 1
End If
If (Asc(d) = 32 Or Asc(d) = 13 Or Asc(d) = 10) And
inWord Then
wordCnt = wordCnt + 1
inWord = False
ElseIf (Asc(d) > 32) And Not inWord Then
inWord = True
End If

If deBg Then d = Asc(d)


Next
cntChar = i1
'Return

End Function
 
L

Larry

Tushar,

Your message would be a lot easier to read without all the abbreviated
words and the lack of capitalization. You may think that writing "no"
for "number" and "txt" for "text" and "fn" for I don't know what and
also not capitalizing any words makes it easier for you to write the
message--but it makes it harder for other people to read it. That's why
there's a common language with a common spelling. People use the same
language with the same spelling so that they can communicate with each
other.

Larry
 
K

Klaus Linke

[...] same as the menu Tools/Word count returns.


Hi Tushar,

(ActiveDocument)
..BuiltInDocumentProperties(wdPropertyPages)
..BuiltInDocumentProperties(wdPropertyWords)
..BuiltInDocumentProperties(wdPropertyCharacters)
..BuiltInDocumentProperties(wdPropertyCharsWSpaces)
..BuiltInDocumentProperties(wdPropertyParas)
..BuiltInDocumentProperties(wdPropertyLines)

Regards,
Klaus
 
P

Peter Hewett

Hi Tushar

If you want info on specific ranges of your document check out the Document
and Range objects ComputeStatistics method.

HTH + Cheers - Peter
 

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