我有一个宏应该每 x 分钟运行一次,以将当前文件保存到指定位置。我使用此链接来帮助编写代码 -> VBA Macro On Timer 样式以每隔设定的秒数运行代码,即 120 秒
但是,当另一个 excel 文件打开并且有人正在处理它时,宏会被触发。
有没有办法中断用户当前的操作并使用消息框或其他东西通知他,以便宏可以继续?
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 & "RD" & RDNum & " " & TestCellNum & " " & dt & ".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