Thread: [Solved] Count characters on the fly
View Single Post
 
Old 04-20-2014, 03:37 AM
NobodysPerfect NobodysPerfect is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default Count characters on the fly

Hi to all

A friend of mine (a journalist) asked me to write a macro—if possible—that counts characters on the fly, as his articles are limited to fixed numbers of characters.

I googled a lot on Application.OnTime and found numerous (timer) examples for Excel. Unfortunately Word's OnTime has no 'Schedule:=False' parameter so I use one OnTime to re-call the procedure until a second OnTime stops the first one.

Code:
Option Explicit
Dim iTimerSet As Double
Dim bTimer As Boolean
 
Sub CountCharsOnTime()
    If Not bTimer Then Exit Sub
    iTimerSet = Now + TimeValue("00:00:01")
    Application.StatusBar = "Anzahl Zeichen = " & _
        ActiveDocument.BuiltInDocumentProperties(wdPropertyCharsWSpaces)
    Application.OnTime iTimerSet, "CountCharsOnTime"
End Sub
 
Sub TimerOnOff()
    bTimer = Not bTimer
    If Not bTimer Then
        Application.OnTime Now, "TimerTaskEnded"
    Else
        CountCharsOnTime
    End If
End Sub

Sub TimerTaskEnded()
    Application.StatusBar = "Fertig ..."
End Sub
The macro works fine within his document, or at least seems to … . But as soon as I copy it into my 'AllMarcos' AddInn it fails in line "Application.OnTime iTimerSet, "CountCharsOnTime"" with a "sub or procedure not found" message.

So my question: What goes wrong with my solution. A macro that only sometimes works does not really help.

Any ideas? Any help appreciated.
NP
Reply With Quote