Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to Thread.Sleep() in VBA

Is there an equivalent to Thread.Sleep() in Access VBA?

like image 545
Johnno Nolan Avatar asked Jan 22 '09 14:01

Johnno Nolan


People also ask

Is there a sleep function in 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.

How do I sleep in VBA code?

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.

How do I wait in VBA?

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.


2 Answers

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  
like image 136
Otávio Décio Avatar answered Sep 20 '22 05:09

Otávio Décio


Another way without using kernel32:

Dim started As Single: started = Timer  Do: DoEvents: Loop Until Timer - started >= 1 
like image 26
DontFretBrett Avatar answered Sep 20 '22 05:09

DontFretBrett