提高倒数计时器的速度

Increase the speed of Countdown Timer

Sub countdown()

Dim time As Date
time = Now()
time = DateAdd("s", 30, time)

Do Until time < Now()
DoEvents
oSh.TextFrame.TextRange = Format((time - Now()), "ss")
Loop
        
End Sub 

我可以使用上面的代码创建一个 30 秒的倒数计时器。 有没有办法在 15 秒内完全显示倒数计时器? 我们可以在 15 秒而不是 30 秒内完成从 30 到 0 的所有数字吗?即在 1 秒内显示 2 个数字。

更新代码:

Sub countdown()

'set the range of the countdown timer
CounterStart = 400
CounterEnd = 100

Dim N1 As Single
N1 = Timer + CounterStart

Do Until N1 < Timer()
DoEvents
oSh.TextFrame.TextRange = ((N1 - (Timer)) + 1)
If oSh.TextFrame.TextRange = CounterEnd Then Exit Sub
Loop

End Sub

问题是,Now 以整秒递增,因此您必须使用 Timer 来获得分秒:

Sub countdown()

    Dim StopTime    As Date
    
    StopTime = DateAdd("s", 15, Now)

    Do
        oSh.TextFrame.TextRange = Second(CDate(2 * (StopTime - (Date + Timer / 86400))))
        DoEvents
    Loop Until Now >= StopTime
        
End Sub