我怎样才能保存我的工作簿在VBA中不停止macros运行?

我有一个VBA代码,在使用application.ontime过了一定的时间之后调用这个方法,

Sub run() Worksheets("Sheet1").Calculate Cells(2, 5).Value = Cells(2, 5).Value + 1 ActiveWorkbook.Save End Sub 

但是,在ActiveWorkbook.Save行之后,macros就停止运行。 如何在保存工作簿后继续运行我的macros,或者在保存时调用macros? 我正在使用excel 2013 btw

这是我的macros调用运行:

 Sub every30seconds() runTime = Now + TimeValue("00:00:30") Application.OnTime EarliestTime:=runTime, Procedure:="run", schedule:=True If Cells(2, 5).Value = 2 Then Application.OnTime runTime, "run", , False Cells(2, 5).Value = Cells(2, 5).Value - 2 End If End Sub 

Application.Ontime方法不允许您安排将来多次发生的事情。 它只允许你设置一次发生。

我相信你以后的代码是

 Sub run() Worksheets("Sheet1").Calculate Cells(2, 5).Value = Cells(2, 5).Value + 1 ActiveWorkbook.Save every30seconds End Sub Sub every30seconds() If Cells(2, 5).Value <> 2 Then runTime = Now + TimeValue("00:00:30") Application.OnTime EarliestTime:=runTime, Procedure:="run", schedule:=True Else Cells(2, 5).Value = Cells(2, 5).Value - 2 End If End Sub