title: vba start stop timers?
body: <p>I want to start and stop two timers in my excel worksheet. This is what i have:</p>
  
  <p>When worksheet is opened, this module is triggered:</p>
  
  <pre><code>Sub SetOpenTimer()
  
  OpenTimer = Now + TimeValue("00:00:10")
  Application.OnTime OpenTimer, "StartTimerShutdownForm"
  
  End Sub
  </code></pre>
  
  <p>After 10 seconds (in this example), the sub <code>startimershutdownform</code> is triggered:</p>
  
  <pre><code>Sub StartTimerShutdownForm()
  
  UserForm1.Show
  
  End Sub
  </code></pre>
  
  <p>This displays a userform where a message is displayed. In the initialize sub in the Userform a sub <code>setformtimer</code> is triggered:</p>
  
  <pre><code>Sub setFormTimer()
  
  FormTimer = Now + TimeValue("00:00:10")
  Application.OnTime FormTimer, "Shutdown"
  
  End Sub
  </code></pre>
  
  <p>If this timer in <code>setformtimer</code> ends, the sub <code>shutdown</code> is triggerd
  this sub closes the workbook, but in the Userform there is a button for the user to cancel the <code>setformtimer</code>:</p>
  
  <pre><code>Sub stopFormTimer()
  
  Application.OnTime EarliestTime:=FormTimer, _
  Procedure:="setOpenTimer", Schedule:=False
  
  End Sub
  </code></pre>
  
  <p>This suppose to stop the <code>setformtimer</code>, but it does not work.
  When this timer is stopped, it suppose to restart the timer that is triggered when the document is being opened, so it all restarts, but the stop timer code does not work. </p>
  
  <p>In the module where  <code>stopFormTimer</code>, <code>setFormTimer</code> and <code>StartTimerShutdownForm</code> is located, at the top I declare these </p>
  
  <pre><code>Dim OpenTimer As Date
  Dim FormTimer As Date
  </code></pre>
  
  <p>What am i missing here? Why cant i stop the timer and restart the first timer?</p>