Abbreviation for "character" in macros

P

pjs

(Using Word 2003 under Windows XP)

I'd like to modify a macro that displays in the formatting toolbar the
running word count so it displays the running character count.

The key line, I believe, is:
.Caption = WdCount

What would I replace WdCount with to yield a character count instead?

Thanks,

pjs
 
P

Pesach Shelnitz

Hi,

Without seeing more of your code, it's difficult to say what exact changes
you should make. It seems to me that WdCount is a variable defined in your
code, so there isn't a simple abbreviation to replace it. In any case,
myDoc.BuiltInDocumentProperties(wdPropertyWords) gives the number of words in
the doc, myDoc.BuiltInDocumentProperties(wdPropertyCharacters) gives the
number of characters without spaces, and
myDoc.BuiltInDocumentProperties(wdCharsWSpaces) gives the number of
characters including spaces, where myDoc is an object representing the
document.
 
P

pjs

Pesach --

Thanks for your note. The code I was trying to modify is a macro for
generating a running word count tally in the active document. It was written
and posted by Allan Wyatt on word.tips.net:

Sub WordCounter()
Set myBar = CommandBars("Formatting")
Set myControls = myBar.Controls
NumButtons = myControls.Count

ButtonLoc = 0
For J = 1 To NumButtons
If myControls(J).Type = msoControlButton Then
ButtonName$ = myControls(J).OnAction
If ButtonName$ = "WordCounter" Then ButtonLoc = J
End If
Next J

If ButtonLoc = 0 Then
ButtonLoc = NumButtons + 1
Set newControl = myControls.Add(Type:=msoControlButton)
newControl.OnAction = "WordCounter"
newControl.Style = msoButtonCaption
End If

Set myRange = ActiveDocument.Content
WdCount = myRange.ReadabilityStatistics(1).Value
With myControls(ButtonLoc)
.Caption = WdCount
End With

Application.OnTime When:=Now + TimeSerial(0, 0, 5), _
Name:="WordCounter"
End Sub

It doesn't look like WdCount is a defined variable. I thought it was
intrinsic to VBA, and there might be a similar term for Character Count.

pjs
________________________________
 
P

Pesach Shelnitz

Hi pjs,

Things are much clearer now. Thanks!

The following is the key line of code here.
WdCount = myRange.ReadabilityStatistics(1).Value

All you need to do in the macro is to change the 1 in this line to 2 to get
a character count instead of a word count. Although WdCount is not declared
as a variable, it clearly is a variable, and its name is of no consequence.
You could change its name to anything you like, as long as you change it
everywhere that this variable appears, or you could leave it as is. The
numbers 1 and 2 are indices in the ReadabilityStatistics collection. The
index 1 is for the number of words, and the index 2 is for the number of
characters. You can also use the property that I described in my previous
posting on the ActiveDocument object to obtain similar, but not identical
numbers.
 

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