General discussion

Locked

Character Count in MS Word

By terrent ·
I'm writing an app in VB (not a macro) that will, among other things, count the characters in a Word (97 or 2000) document according to corporate specified parameters. These parameters are still being clarified, so I may need to adjust them and recompile for analysis. So far, it looks like the standard will be identical with what comes with Word (such as: returns are not counted while spaces are) except tabs should be counted as characters. How can this be done using the MS Word object in VB6?
Thank you

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Character Count in MS Word

by Glen_McLeod In reply to Character Count in MS Wor ...

This code uses the internal Word counter:

Function DocumentCharacters(ByVal sFile As String) As Long
Dim oWord As Word.Application
Dim oDoc As Word.Document

Set oWord = New Word.Application
Set oDoc = oWord.Documents.Open(sFile)

DocumentCharacters = oDoc.Characters.Count

oDoc.Close
Set oDoc = Nothing
Set oWord = Nothing
End Function

You have to set a reference to the Word object library in order to use the declarations "Word.Application" and "Word.Document"

Glen

Collapse -

Character Count in MS Word

by terrent In reply to Character Count in MS Wor ...

Ok, I got that. But the only changes in what gets counted are with or without spaces. I need to count tabs and possibly other stuff that MS doesn't already count.
Thanks anyway.

Collapse -

Character Count in MS Word

by andrew In reply to Character Count in MS Wor ...

Try this:
set a reference to the Word9 Object Library (MSWORD9.OLB)

add this code:

Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim lChars As Long
Set oApp = New Word.Application
Set oDoc = oApp.Documents.Open("c:\test.doc")
lChars = oDoc.ComputeStatistics(wdStatisticCharactersWithSpaces)
MsgBox lChars

Collapse -

Character Count in MS Word

by terrent In reply to Character Count in MS Wor ...

Ok, I got that. But the only changes in what gets counted are with or without spaces. I need to count tabs and possibly other stuff that MS doesn't already count.
Thanks anyway.

Collapse -

Character Count in MS Word

by terrent In reply to Character Count in MS Wor ...

This question was closed by the author

Back to Desktop Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums