Excel VBA秒表:添加暂停按钮?

时间:2017-06-16 20:35:06

标签: excel-vba vba excel

我有一个带有开始/停止/清除按钮的秒表,可以将时间发布到我的电子表格中的其他单元格。我想添加一个暂停按钮,允许用户暂停和恢复他们停止的计时器,但它会继续恢复并将过渡时间传递给总计。例如,我点击开始并等待5分钟,然后在5:00点击暂停。我再等2分钟,然后点击恢复,计时器在7:00,7:01,7:02等处重新启动。如何创建有效的暂停/恢复按钮并告诉excel不要包含时间什么时候恢复计数?

    Dim NextTick As Date, t As Date
Sub StartStopWatch()
t = Time
Call StartTimer
End Sub

Sub StartTimer()
NextTick = Time + TimeValue("00:00:01")
Range("M1").Value = Format(NextTick - t - TimeValue("00:00:01"), "hh:mm:ss")
Application.OnTime NextTick, "StartTimer"

End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=NextTick, Procedure:="StartTimer", Schedule:=False
End Sub

Sub ResetTimer()
Range("M1").ClearContents
Range("N1").ClearContents
Range("L2").ClearContents
End Sub

Sub PauseButton()

If Range("L2").Value = "" Then

    Range("L2").Value = "Paused"

    Application.OnTime EarliestTime:=NextTick, Procedure:="StartTimer", Schedule:=False

Else
    Range("L2").ClearContents
    Application.OnTime EarliestTime:=NextTick, Procedure:="StartTimer", Schedule:=True

End If

End Sub

1 个答案:

答案 0 :(得分:1)

我想是这样的

(define listAux '())
(define (fibTail n1 n2 c)
  (if (= c 0)
      (appendList -1)
      (begin
        (appendList n2)
        (fibT (+ n1 n2) n1 (- c 1))
        )))

(define (appendList n)
  (if (= n -1)
      listAux
      (append (list n) listAux)))


(define (fib n)
  (fibTail 1 0 n))