Menuへ
Windows APIを使用したタイマー



シートコード
'Windowsが起動してからの経過時間 API
Private Declare Function GetTickCount Lib "kernel32" () As Long

'タイマー
Private Sub ExTimer(tim As Long)
    Dim st As Long
    
    tim = tim * 1000
    '開始時間を取得
    st = GetTickCount
    DoEvents
    Do
        If GetTickCount - st >= tim Then
            '時間が経過した
            Exit Do
        End If
        DoEvents
    Loop
End Sub

コマンドボタンクリックイベント
Private Sub CommandButton1_Click()
    CommandButton1.Caption = "Start"
    '10秒間タイマー
    ExTimer 10
    CommandButton1.Caption = "Stop"
End Sub

実行結果
開始コマンドボタン




Topへ