Back to main page
Programs by Mike
Technical Writing by Mike
Graphic design by Mike
E-mail Mike

Character counting in Word 97

Word 97 can count characters even faster than WP51 can. This is because with a Word 97 macro we can access the Document Properties and have the computer tell us how exactly how many characters are in the current document. Then all we all need to do is divide the total number of characters by whatever number we use for our total characters per line. (In the example above we used 65.)

Quick and dirty Word 97 line counter

Look at the macro below:

Sub count()

Dim line1 As String, line2 As String
line1 = Str(ActiveDocument.Characters.count / 65)
line2 = Left(line1, 7)
MsgBox "This document contains: " + Chr(13) + C + " lines", vbOKOnly + vbInformation, "Line Count (65 Ch)"

End Sub

This macro starts off with a name, denoted by Sub. So the name of this macro is "count." The next line declares the variables we will be using, in this case the variable named "line1" containing string data, and the variable named "line2" also containing string data. (The word "string" is just a fancy way of saying "a group of characters.")

The next line sets the variable b equal to the number of characters in the active document divided by 65. The line that says "line2 = Left(line1, 7)" is strictly for formatting purposes. This line assigns the value stored in the variable line1 to the variable line2 and tells Word to only display a certain number of characters starting from the left of the string, in this case the whole number followed by 2-3 decimal places. (If this line wasn't there Word would display the decimal value of the total characters divided by 65.)

The MsgBox line tells Word to show a dialog box that states "This document contains: " then a start a new line (Chr(13)), then the 7 digit number contained in line2, then the word "lines." This dialog box will also display an OK button and the information icon. The title of the dialog will be "Line Count (65 Ch)."

Of course, you can change the line count parameters so that Word will divide by a different number of characters by replacing the 65 with whatever number you normally divide by.

Copyright 1999 by Mike DeTuri (reprinted from Computer Solutions Vol. 1, Issue 2)