Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word OnTime method (97 2000 2002)

    Hi there!

    Is it true, that in Word one can only set *one* ontime trigger to a sub at the time? (so the below would only run SubToRun on the LAST time):

    For I=1 to 10
    Application.OnTime Now()+Timeserial("00:00:" & format(I,"00")) , "SubToRun"
    Next
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word OnTime method (97 2000 2002)

    The Online help for both Word 97 VBA and Word 2002 VBA mentions explicitly that in Word, only one background timer can be set using OnTime. If you start a new timer before an existing timer has run, the existing timer will be canceled. MSDN states the same.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word OnTime method (97 2000 2002)

    Sheesh, that is a pity. In XL, one can set as many timers (even to the same sub) as one wishes.

    Should've read OLH more carefully.

    Thanks.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word OnTime method (97 2000 2002)

    Don't you just love <img src=/S/love.gif border=0 alt=love width=15 height=15> the consistency between the different parts of the Office suite?

    Excel supports multiple timers with OnTime.
    Word supports only a single timer with OnTime.
    PowerPoint doesn't have a general OnTime, only transition time for slides.
    Access supports one timer for each form through the OnTimer event.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word OnTime method (97 2000 2002)

    Great.

    As you may have seen, I'm writing an application that does timed exports of VBA code modules ad UserForms.
    In XL I have this running almost satisfactorily.

    What I have to do for this application is set a timer that will keep rescheduling itself.

    But when one is debugging (other) code, a set timer that reaches it's scheduled time will invoke an error message (Unable to execute code while in step mode or something like that) and the sub that was scheduled to be run will not run, thus breaking the chain of scheduling <grrrr>.

    Since the application is all about working in the VBE (in which one often is in debug mode...) I need a reliable method of scheduling.

    So what I do in Excel is set 10 OnTime events. Should one be in debug mode when the first fires, one will always be "saved" because number 2 (or 3 or 4,...) will fire.
    The first OnTime event that DOES fire, cancels the other 9 and sets 10 new ones. This minimizes the chance of breaking the chain of OnTime events.

    Since Word does not have this option of setting multiple timers, I'm wondering what I can do about this.
    I tried using the SetTimer API, but that crashes Word (works reliably in XL2000, how consistent). <sigh>
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word OnTime method (97 2000 2002)

    Okay, it's way more overhead, but could you add a reference to Excel to your Word project and automate Excel's timer? (Maybe the question is, even if you could, would it be worth doing?)

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word OnTime method (97 2000 2002)

    I thought about that, but indeed decided not to. It would (for instance) severely slowdown startup of Word. It is also error prone. If my project (for whatever reason) gets reset, I'll probably leave an XL session around in memory.

    I decided to retry the SetTimer API yesterday and got that working!
    Anyone interested in that piece of code give a hollar.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •