title: Stopping the OnTime event
body: <p>I have come across posts which explain "To cancel a pending OnTime event, you must provide the exact time that it is scheduled to run".</p>
  
  <p>Should I supply the time at which the event was run the very first time or should I supply the time at which the event will be triggered next?</p>
  
  <p>I have tried both version of StopTimer. Both give me</p>
  
  <blockquote>
    <p>Method OnTime of object _Application failed</p>
  </blockquote>
  
  <pre><code>Option Explicit
  
  Private Sub Workbook_Open()
      count = 1
      Call test
  End Sub
  
  
  Public runwhen As Double
  Public Const runwhat As String = "TheSub"
  Public firstrunTime As Double
  Public count As Integer
  
  
  Sub test()
      If count = 1 Then
          runwhen = Now + TimeSerial(0, 0, 5)
          firstrunTime = runwhen
      Else
          runwhen = Now + TimeSerial(0, 0, 5)
      End If
  
      Application.OnTime runwhen, "TheSub"
  End Sub
  
  
  Sub TheSub()
      MsgBox "Hi!!!!!!"
      count = count + 1
      Call test
      If count = 5 Then
          StopTimer
      End If
  End Sub
  
  
  'First Version of StopTimer
  Sub StopTimer()
      Application.OnTime firstrunTime, "TheSub", , False
  End Sub
  
  
  'Second Version of StopTimer
  Sub StopTimer()
      runwhen=now+TimeSerial(0,0,5)
      Application.OnTime runwhen, "TheSub", , False
  End Sub
  </code></pre>
  
  <p>I made changes to procedure TEST below and now I am using third version of STOPTIMER but my code gives me same error.</p>
  
  <pre><code>Sub test()
      If count = 1 Then
          runwhen = Now + TimeSerial(0, 0, 5)
          firstrunTime = runwhen
      Else
          runwhen = Now + TimeSerial(0, 0, 5)
      End If
      If count &lt;&gt; 5 Then
          Application.OnTime runwhen, "TheSub"
      Else
          Call StopTimer
      End If
  End Sub
  </code></pre>