Delay macro to allow events to finish

后端 未结 1 1622
广开言路
广开言路 2020-12-12 08:20

While attempting to access an external API function set from within a macro I found it necessary to add in a delay to allow time for the external API to process a selection.

相关标签:
1条回答
  • 2020-12-12 08:46

    Instead I implemented the delay using the functions Now and DateAdd:

    Function Delay(Seconds As Long)
        Dim StopTime As Date: StopTime = DateAdd("s", Seconds, Now)
        Do While Now < StopTime
            DoEvents
        Loop
    End Function
    

    Updated below for millisecond precision

    Function Delay(Seconds As Single)
        Dim StopTime As Single: StopTime = Timer + Seconds
        Do While Timer < StopTime
            DoEvents
        Loop
    End Function
    
    0 讨论(0)
提交回复
热议问题