+ Reply to Thread
Results 1 to 6 of 6

Application OnTime Refresh

  1. #1
    Registered User
    Join Date
    02-27-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    25

    Application OnTime Refresh

    Good morning,

    I have a macro named "UpdateScreen" that ends with Application.OnTime Now + TimeValue("00:01:00"), "UpdateScreen" so it runs it again 1 minute later.
    The problem is that the workbook contains a "Refresh" button so it can be refreshed at any time manually. On running this macro it triggers the OnTime again, meaning itll run twice in the space of 60 seconds.
    The more you click it the more it runs in a minute.

    Is there a way to cancel the OnTime just before it is called so that the timer resets whenever the "UpdateScreen" macro ends?

    Thank you

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Application OnTime Refresh

    To cancel an OnTime you need to store the exact time the event is scheduled and call OnTime again passing that time and setting the Schedule Parameter to False.

    This means you need to declare a module level variable to hold the time, set that variable with the calculated event time and then call OnTime.

    Narrative answer only, using a phone, but there are plenty of examples around the forum.

  3. #3
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Application OnTime Refresh

    Yes. you must declare a module-level variable to track the most recently-defined timing event.
    Please Login or Register  to view this content.
    NOTE: Comparing NextTick to Now as a conditional test is unreliable. Just assume you need to stop the clock.

    Please click the Add Reputation star below any helpful posts, and if you have your answer, mark your thread as SOLVED (Thread Tools up top). Thanks!-Lee
    Last edited by leelnich; 05-15-2017 at 04:08 AM.

  4. #4
    Registered User
    Join Date
    02-27-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Application OnTime Refresh

    Perfect thank you cytop, Leelnich just provided the code for exactly what you were referring to so thank you

  5. #5
    Registered User
    Join Date
    02-27-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Application OnTime Refresh

    Thank you Lee that's done the job.
    Thank you again.

  6. #6
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Application OnTime Refresh

    You're welcome! And thanks for the rep.
    BTW, Excel controls the Timer, NOT your workbook. To avoid weirdness, consider calling StopClock from the Workbook_Close event.
    Last edited by leelnich; 05-15-2017 at 04:19 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA - Application.Ontime Cancel Fails to Method 'ONTIME' of Object 'Application'
    By LordAzuRa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2016, 03:21 PM
  2. Bloomberg BDH Refresh Via Macro Loop Application.Ontime
    By firefly2k8 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2014, 08:23 AM
  3. Application.ontime
    By hatrickx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2013, 09:18 PM
  4. [SOLVED] Application.OnTime VBA
    By Anka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-26-2013, 05:41 PM
  5. [SOLVED] Help with Application.OnTime (was Application.Wait Now)
    By Walter12 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-29-2012, 01:18 PM
  6. OnTime Refresh function help please
    By gloops in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2007, 09:47 AM
  7. [SOLVED] Help with Application.OnTime
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2006, 01:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1