hakeの日記

Windows環境でプログラミングの勉強をしています。

EXCEL VBAメモ - タイマー処理

Option Explicit

Sub testTimer()
    Dim sec As Long: sec = 10 ' タイマー時間
    Dim targetTime As Date

    ' 現在時刻 + タイマー時間
    targetTime = DateAdd("s", sec, Time)

    Do
        ' セルに残り秒数を表示
        Range("A1").Value = DateDiff("s", Time, targetTime)
        
        DoEvents
    Loop While (Range("A1").Value <> 0)
    MsgBox "時間です。"
End Sub