title: Code to run macro on time interval?
body: <p>How can I set a macro to run at a specific time and then at set intervals afterwards? I would like it to run at the top of each hour so I would like to start it at 07:00AM for example and then every hour after I want it to run again. Here is the code:</p>
  
  <pre><code>Sub Refresh_All()
  '
  ' Refresh_All Macro
  '
  ' Keyboard Shortcut: Ctrl+Y
  '
      ChDir "Q:\Quality Control"
      Workbooks.Open Filename:= _
          "Q:\Quality Control\Internal Failure Log - Variable Month.xlsm"
      Dim endTime As Date
      endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
  DoEvents
      Loop
      ActiveWorkbook.RefreshAll
         endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.Save
      endTime = DateAdd("s", 5, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
      ActiveWindow.Close
      ChDir "Q:\Reports"
      Workbooks.Open Filename:= _
          "Q:\Reports\Finished-Transfer Report-variable month.xlsm"
          endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.RefreshAll
       endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.Save
          endTime = DateAdd("s", 5, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWindow.Close
      ActiveWorkbook.RefreshAll
          endTime = DateAdd("s", 10, Now())
      Do While Now() &lt; endTime
          DoEvents
      Loop
  ActiveWorkbook.Save
  End Sub
  </code></pre>