How to give a time delay of less than one second in excel vba?

后端 未结 10 2159
孤街浪徒
孤街浪徒 2020-11-29 06:14

i want to repeat an event after a certain duration that is less than 1 second. I tried using the following code

Application.wait Now + TimeValue (\"00:00:01\         


        
10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 07:00

    You can use an API call and Sleep:

    Put this at the top of your module:

    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    

    Then you can call it in a procedure like this:

    Sub test()
    Dim i As Long
    
    For i = 1 To 10
        Debug.Print Now()
        Sleep 500    'wait 0.5 seconds
    Next i
    End Sub
    

提交回复
热议问题