Is there an equivalent to Thread.Sleep()
in Access VBA?
VBA Sleep function is a windows function present under windows DLL files which is used to stop or pause the macro procedure from running for a specified amount of time after that certain amount of we can resume the program.
Follow the below steps to use Sleep Function in Excel VBA: Step 1: Go to the Developer tab and click on Visual Basic to open VB Editor. Step 2: Once the VB Editor is open click on Insert Tab and then click on modules to insert a new module. Step 3: Now use the declaration statement to use sleep function.
Wait method only accepts one argument: time. To wait 5 seconds, like I did in the demo above, you feed Application. Wait the current time with the Now function. Then, you use the TimeValue function to add 5 seconds to the current time.
Declare Sub Sleep Lib "kernel32" Alias "Sleep" _ (ByVal dwMilliseconds As Long)
Use the following syntax to call the Sleep function:
Sub Sleep() Sleep 1000 'Implements a 1 second delay End Sub
Another way without using kernel32:
Dim started As Single: started = Timer Do: DoEvents: Loop Until Timer - started >= 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With