VBA计时器 – 减去等待用户input的时间
我正在使用这个在spreadsheetguru.com上find的方法来计算运行一个macros的时间:
Sub CalculateRunTime_Minutes() 'PURPOSE: Determine how many minutes it took for code to completely run 'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault Dim StartTime As Double Dim MinutesElapsed As String 'Remember time when macro starts StartTime = Timer '***************************** 'Insert Your Code Here... '***************************** 'Determine how many seconds code took to run MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss") 'Notify user in seconds MsgBox "This code ran successfully in " & MinutesElapsed & " minutes", vbInformation End Sub
它适用于我,但在我的代码中,有多个用户input提示。 有些只是OKbutton,其他的则是带有多个button的用户表单。
我如何计算运行macros所需的时间减去等待用户点击button的时间?
基于你的代码是这样的:
Sub CalculateRunTime_Minutes() Dim StartTime1 As Double, StartTime2 As Double, StartTime3 As Double Dim StopTime1 As Double, StopTime2 As Double Dim MinutesElapsed As String StartTime1 = Timer 'your code StopTime1 = Timer 'user input1 StartTime2 = Timer 'your code StopTime2 = Timer 'user input2 StartTime3 = Timer 'your code MinutesElapsed = Format(((Timer - StartTime3) + (StopTime2 - StartTime2) + (StopTime1 - StartTime1)) / 86400, "hh:mm:ss") MsgBox "This code ran successfully in " & MinutesElapsed & " minutes", vbInformation End Sub
你能否实施某种PauseTime检查?
我的VBA很远,但…
Dim arrayPausetime() as double Dim formStartTime as double Dim formStopTime as double.
每次启动需要用户input的表单时,都会获取formStartTime的时间戳,当您退出该表单时formStopTime也一样。
添加(formStopTime – formStartTime)到你的arrayPausetime和你的macros的末尾:
dim finalTime as double for each (double pausetime in arrayPausetime) finalTime = finalTime + (Timer - StartTime) - pausetime
希望它有助于头脑风暴! 🙂