我想在Excel中停止当前正在运行的计时器。到目前为止,我已经使用下面的代码在excel中启动计时器,但是我想放置一个按钮,该按钮可以通过VBA在excel表格中停止当前正在运行的计时器。
Dim xRng As Range
Dim oDict As Object
Sub StartTimer()
Set xRng = Application.ActiveSheet.Range("D2")
Set oDict = CreateObject("Scripting.Dictionary")
Call PopDict
Call Timer
End Sub
Sub Timer()
Dim gCount As Date gCount = Now + TimeValue("00:00:01")
Application.OnTime gCount, "ResetTime"
End Sub
Sub ResetTime()
If xRng.Value > 0 Then
xRng.Value = xRng.Value - TimeSerial(0, 0, 1)
End If
xRng.Value <= 0 Then
xRng.EntireRow.Interior.ColorIndex = 43
If xRng.Row =oDict(xRng.Offset(, -2).Value) Then
MsgBox xRng.Offset(, -2).Value & " Committed time is over"
End If
Set xRng = xRng.Offset(1) 'Move to next cell in colum
If xRng.Value = vbNullString Then
MsgBox "All tasks are Over and CR is ready for the deployment"
Exit Sub
End If
End If
Call Timer
End Sub
Sub PopDict()
Dim lRow As Long
lRow = 2
Do Until ActiveSheet.Cells(lRow, 2).Value = vbNullString
oDict(ActiveSheet.Cells(lRow, 2).Value) = lRow
lRow = lRow + 1
Loop
End Sub