Search code examples
vbapowerpoint

Having number above 60 in "ss" format


Global time As Date

Sub countdown()
time = Now()
time = DateAdd("s", 120, time)

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

The timer starts from 60 and ends at 00. Then the same repeats. Is it possible to start the timer from 120 directly? How can we go about it?


Solution

  • Use DateDiff:

    Global StopTime As Date
    
    Sub countdown()
    
        StopTime = DateAdd("s", 120, Now)
    
        Do Until StopTime < Now
            DoEvents
            oSh.TextFrame.TextRange = DateDiff("s", Now, StopTime)
        Loop
    
    End Sub