title: Application On time
body: <p>I am facing few issues with my <code>OnTime</code>-method in vba. The code is supposed to run every 30 minutes, but somehow it runs a few more times in between. I am assuming this is because several <code>OnTime</code>-methods might be running when I reset and rerun the code. So I wanted to kill the on time function but getting error. Here is my code below:</p>
  
  <p>Initial code:</p>
  
  <pre><code>Sub autorefresh()
      dim timetorun
  
      timetorun = Now + TimeSerial(0, 30, 0)
  
      Application.OnTime timetorun, "manager" 'this runs the macro manager which
                                              'runs several other macros and in
                                              'the end calls this macro again in
                                              'order to reset the timetorun counter
  End Sub
  </code></pre>
  
  <p>I revised the below code to reset the ontime if needed. </p>
  
  <pre><code>Public timetorun As Date    'so that timetorun can be used in both the functions
  
  Sub autorefresh()
  
      timetorun = Now + TimeSerial(0, 30, 0)
      Application.OnTime timetorun, "manager"
  
  End Sub
  
  Sub killontime()
  
      Application.OnTime earliesttime:=timetorun, procedure:="manager", schedule:=False   '&lt;~~this line gives the error
  
  End Sub
  </code></pre>