DoEvents function

Category: Program Flow / Interaction

Summary

Yields execution so the operating system can process other events (like keystrokes, mouse clicks, repaint requests) before resuming code.

Syntax

Yields execution so that the operating system can process other events.

Example

Example
This example uses the DoEvents function to cause execution to yield to the operating system once every 1000 iterations of the loop. DoEvents returns the number of open Visual Basic forms, but only when the host application is Visual Basic.
' Create a variable to hold number of Visual Basic forms loaded
' and visible.
Dim I, OpenForms
For I = 1 To 150000 ' Start loop.
If I Mod 1000 = 0 Then ' If loop has repeated 1000 times.
OpenForms = DoEvents ' Yield to operating system.
End If
Next I ' Increment loop counter.

Microsoft Support Page

https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/doevents-function

Back to Functions