title: Interrupt work (in any active files) to run macro every x minutes - Excel VBA
body: <p>I have a macro that is supposed to run every x minutes to save the current file to a specified location. I used this link to help write the code ->
  <a href="https://stackoverflow.com/questions/2319683/vba-macro-on-timer-style-to-run-code-every-set-number-of-seconds-i-e-120-secon">VBA Macro On Timer style to run code every set number of seconds, i.e. 120 seconds</a></p>
  
  <p>However, the macro gets tripped up when another excel file is open &amp; someone is working on it.</p>
  
  <p>Is there a way to interrupt the current operation by the user &amp; inform him using a message box or something so that the macro can then proceed?</p>
  
  <pre><code>Dim TimeToRun, k, RDNum, DestinationFolderName, MasterFile, TestCellNum
  
  Sub ScheduleIt()
      TimeToRun = Now + TimeValue("00:00:10")
      Application.OnTime TimeToRun, "CopyPriceOver"
  End Sub
  
  Sub CopyPriceOver()
      Windows(MasterFile).Activate
      Worksheets("Save Log").Activate
  
      dt = Format(CStr(Now), "mm-dd-yyyy hh-mm-ss")
      MasterFileName = DestinationFolderName &amp; "RD" &amp; RDNum &amp; " " &amp; TestCellNum &amp; " " &amp; dt &amp; ".xlsb"
      ActiveWorkbook.SaveAs Filename:=MasterFileName, FileFormat:=xlExcel12, CreateBackup:=False
  
      Call ScheduleIt
  End Sub
  Sub AutoOpen()
      k = 1
      Worksheets("Test Header").Activate
      RDNum = Range("C4").Value
      LR = Cells(Rows.Count, "I").End(xlUp).Row 'Sets the last row
      TestCellNum = Cells(LR, "I").Value
      DestinationFolderName = "\\C:\Directory\"
      MasterFile = ThisWorkbook.Name
  
      Call ScheduleIt
  End Sub
  
  Sub AutoClose()
      Application.OnTime TimeToRun, "CopyPriceOver", , False
  End Sub
  </code></pre>