修改[中途] 谢谢你YowE3K,你的评论后代码已被修改,但它不能正常工作...... 两个定时器都独立运行,但只有在它们单独运行时才能运行。在我转向两个时刻的那一刻,他们开始计时每2秒而不是应该是一个。我知道它可能与这部分相关" Application.OnTime SchdTime + OneSec," Sheet1.setImmediate"但我不知道如何在这里指定单元格。目前,当他们一起使用时,他们都会向Sheet1添加一秒。
此外,重新打开文档后从00:00:00开始的计时器问题仍然存在。
以下是代码 - 请注意这个代码适用于ToggleButtons:
Dim StopTimer As Boolean
Dim SchdTime As Date
Dim Etime As Date
Dim SchdTime2 As Date
Dim Etime2 As Date
Const OneSec As Date = 1 / 86400#
Private Sub Start_Stop_1_Click()
If Start_Stop_1 = True Then
StopTimer = False
SchdTime = Now()
[K3].Value = Format(Etime, "hh:mm:ss")
Application.OnTime SchdTime + OneSec, "Sheet1.setImmediate"
Else
StopTimer = True
Beep
End If
End Sub
Private Sub Start_Stop_2_Click()
If Start_Stop_2 = True Then
StopTimer = False
SchdTime2 = Now()
[K4].Value = Format(Etime2, "hh:mm:ss")
Application.OnTime SchdTime2 + OneSec, "Sheet1.setImmediate"
Else
StopTimer = True
Beep
End If
End Sub
Sub setImmediate()
If Start_Stop_1 = True Then
[K3].Value = Format(Etime, "hh:mm:ss")
SchdTime = SchdTime + OneSec
Application.OnTime SchdTime, "Sheet1.setImmediate"
Etime = Etime + OneSec
Else: StopTimer = True
'Don't reschedule update
End If
If Start_Stop_2 = True Then
[K4].Value = Format(Etime2, "hh:mm:ss")
SchdTime2 = SchdTime2 + OneSec
Application.OnTime SchdTime2, "Sheet1.setImmediate"
Etime2 = Etime2 + OneSec
Else: StopTimer = True
'Don't reschedule update
End If
End Sub