• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How do I stop an auto-refreshing macro?

XLPadawan

Member
On the auto tab I have two buttons attached to macros. The Run Clock macro gets the clock going, but I can't find a way to stop the clock VBA-wise so I can make a macro for the Stop Clock button that will stop the clock. Help!
 

Attachments

  • CLOCK w H-M-S.xlsm
    91.5 KB · Views: 4
You have:
Application.OnTime DateAdd("s", 1, Now), "Calculate_Range"
in the Calculate_Range macro, which reschedules a run of itself.
Make that line conditional:
if x then Application.OnTime DateAdd("s", 1, Now), "Calculate_Range"
where x is something you test; it could be a global variable set by a StopClock macro, it could be the contents of a cell on a sheet somewhere which is adjusted by the StopClock macro.
It will be 'cleaner' if the StartClock macro is a separate macro that sets x to false (or whatever) and then calls the Calculate_Range macro.
See attached.
 

Attachments

  • Chandoo44846CLOCK w H-M-S.xlsm
    97.8 KB · Views: 6
Last edited:
Back
Top