To pause an Excel VBA macro until a particular time, use Application.Wait, for example Application.Wait Now + TimeSerial(0, 0, 5) to wait about five seconds. It is suitable for simple pauses, but it blocks the macro and is not a precise millisecond timer; for other timing needs, consider Windows’ Sleep API, DoEvents, or Application.OnTime.
What “wait” means in Excel VBA
VBA does not have a general-purpose command named Wait that pauses a procedure by itself. In Excel, the usual built-in choice is the Application object’s Wait method. It tells Excel to suspend activity until a specified date and time, after which the next VBA statement can run.
That makes it useful when a macro needs a short, fixed delay—for example, allowing a visible status message to remain on screen or giving a simple external process time to respond. A delay is not the same as a confirmation, though: waiting five seconds does not prove that a file finished downloading, a query refreshed, or another application completed its work.
The distinction matters because a fixed pause can be too short on a slow computer and unnecessarily long on a fast one. If the macro depends on a particular event or result, it is usually safer to check for that condition and stop after a reasonable timeout.
How Application.Wait works
The method takes a time value, normally a VBA Date. Adding a duration to Now is a convenient way to create a target in the future. The expression Now + TimeSerial(0, 0, 5) means the current date and time plus five seconds. TimeSerial accepts hours, minutes, and seconds, so TimeSerial(0, 2, 0) represents two minutes.
Application.Wait returns a Boolean value: it returns True when the target time is reached. While the method is waiting, the macro does not continue to its next line. Excel activity is suspended, and the workbook interface may appear unresponsive. Microsoft documents that background work such as recalculation and printing can continue, but that should not be treated as a guarantee that every external task or user interaction will proceed as expected.
Use a future time. If the requested time is already in the past, the intended pause has effectively elapsed, so the macro may continue immediately. For ordinary short delays, calculate the target from Now rather than hard-coding a clock time.
A basic five-second pause
This standalone example waits for five seconds, then displays a message. Put it in a standard VBA module. Before running any macro, save a copy of the workbook: VBA changes cannot be reversed with Ctrl+Z.
Option Explicit
Sub PauseFiveSeconds()
' Save a copy of the workbook before running this macro.
Dim resumeAt As Date
Dim waitCompleted As Boolean
resumeAt = Now + TimeSerial(0, 0, 5)
waitCompleted = Application.Wait(resumeAt)
If waitCompleted Then
MsgBox "The five-second pause is over."
End If
End Sub
In this example, the message appears after the wait finishes. You can replace the message with the next operation in your procedure. The return value is useful when a procedure needs to distinguish a completed wait from a wait that did not reach its target, rather than simply calling the method without checking it.
Timing accuracy and short delays
Application.Wait is intended for waiting until a date and time, not for precise high-resolution timing. A request for a fraction of a second may not behave like a dependable millisecond timer. Windows scheduling, Excel’s workload, and other running processes can also affect when a macro resumes. Do not use it to synchronize time-critical operations, control a device, or measure how long code takes with fine precision.
For a pause of several seconds, the built-in method is generally straightforward. For a very short pause on Windows, the Windows API function Sleep accepts a duration in milliseconds. Despite the unit, it is still subject to operating-system scheduling and should not be mistaken for exact real-time timing. The following declaration supports VBA7, used by current Microsoft 365 Excel, and includes a branch for older VBA versions:
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub PauseHalfSecond()
' Save a copy of the workbook before running this macro.
Dim delayMilliseconds As Long
delayMilliseconds = 500
Sleep delayMilliseconds
End Sub
This declaration is Windows-specific. Do not paste it into a workbook intended to run unchanged on Mac; kernel32 is a Windows library. For portable VBA, use a suitable built-in approach or design the procedure so it does not rely on a tiny fixed pause.
Wait compared with Sleep and DoEvents
These techniques solve different problems. Choose based on what the macro needs to accomplish, not simply on which command looks shortest.
Application.Wait: Waits until a specified date and time. It is easy to use for a basic pause measured in seconds, but the running procedure is stopped and Excel may not respond normally.Sleep: Pauses the current Windows VBA thread for a number of milliseconds. It requires a Windows API declaration, is not portable to Mac, and does not make the macro continue doing other work.DoEvents: Yields control so Windows and Excel can process queued events, including some user-interface activity. It is not a timer by itself; a loop must decide when to resume.Application.OnTime: Schedules a procedure to run at a later time instead of holding the current procedure in a continuous wait. It is useful when Excel can return control in the meantime.
In particular, adding DoEvents to a loop makes Excel more responsive, but it can also allow another event or macro to run before the first procedure finishes. That re-entry can cause duplicate work or conflicting edits. Use it deliberately, and prevent the same operation from starting twice if that would be unsafe.
Waiting for a condition instead of guessing
If the next step depends on a cell changing, a file appearing, or a process finishing, poll for that condition rather than always waiting an arbitrary number of seconds. A polling loop checks repeatedly and exits as soon as the result is ready. Set a timeout as well, so a missing response does not leave the macro running forever.
For example, the following code checks whether cell A1 on Sheet1 contains the text Done. It checks for up to 30 seconds and uses DoEvents between checks so Excel can process pending events. The worksheet name and cell are assumptions for this example; change them to match the workbook.
Option Explicit
Sub WaitForDoneStatus()
' Save a copy of the workbook before running this macro.
Dim deadline As Date
Dim statusText As String
deadline = DateAdd("s", 30, Now)
statusText = CStr(ThisWorkbook.Worksheets("Sheet1").Range("A1").Value)
Do While statusText <> "Done" And Now < deadline
DoEvents
statusText = CStr(ThisWorkbook.Worksheets("Sheet1").Range("A1").Value)
Loop
If statusText = "Done" Then
MsgBox "The status is complete."
Else
MsgBox "Timed out waiting for the status."
End If
End Sub
This example assumes A1 contains ordinary text. If the cell can contain an Excel error value, handle that case before converting it to a string. Also consider how frequently the loop should check: a small delay between checks can reduce repeated work, while an unthrottled loop may consume unnecessary processor time.
Waiting for refreshes and scheduled work
A fixed delay is a weak way to wait for a data refresh. Refresh duration can change with network conditions, data size, authentication, or the source system. Where possible, use the completion or status mechanism provided by the specific connection or operation, then continue only after it reports that work is finished. Excel’s Application.CalculateUntilAsyncQueriesDone method can be relevant for pending asynchronous OLE DB and OLAP queries, but it is not a universal wait command for every connection, add-in, or external application.
If the task can be split into separate stages, Application.OnTime can schedule a named procedure to run later. The current procedure can finish and return control to Excel rather than sitting in a blocking pause. This approach requires care: the scheduled procedure must be available when it is due, and a workbook closing or a changed schedule can affect the plan. For a simple pause inside one short macro, Application.Wait is usually easier; for a longer workflow, scheduling or event-driven logic is often a better fit.
Common problems and safer use
A macro that seems frozen during a wait may be behaving as designed: the procedure is paused, and Excel may not repaint or accept input normally. Avoid long blocking waits when people need to keep working in the workbook. If a long operation is unavoidable, show a clear status before it begins and consider whether the work can be divided into smaller scheduled steps.
Another frequent mistake is assuming that a pause guarantees completion. If an external process takes longer than expected, the macro can continue too early; if it finishes quickly, the macro wastes time. Prefer checking a reliable completion signal, and include a timeout with a useful message or recovery path.
Use macros only from workbooks and sources you trust. A wait command does not make a macro safe: VBA can edit or delete workbook content and interact with files or other applications. Keep a backup before running unfamiliar code, and remember that Ctrl+Z cannot undo changes made by a macro. If a procedure appears stuck, Excel’s Esc or Ctrl+Break may interrupt some VBA operations, but interruption can leave work incomplete; do not rely on it as a substitute for a timeout.
Windows and Mac considerations
Application.Wait is an Excel VBA method, while the Sleep example above calls the Windows kernel32 library. Consequently, that API declaration is not a cross-platform solution and will not work as written in Excel for Mac. If a workbook must run on both platforms, avoid Windows API dependencies or provide platform-specific code with appropriate conditional compilation and testing.
The Windows shortcut to open the VBA editor is Alt+F11. On Mac, the editor shortcut is usually Option+F11; depending on the keyboard and macOS settings, you may also need Fn. The exact key behavior can vary by keyboard. Excel for the web does not run VBA macros, so these techniques require the desktop Excel application.
Frequently Asked Questions
How do I make Excel VBA wait for five seconds?
Use Application.Wait Now + TimeSerial(0, 0, 5). It pauses the macro until the target time; Excel may be less responsive while it waits.
Does Application.Wait freeze Excel?
It suspends Excel activity while the macro waits, so the interface can appear frozen. Some background work may continue, but the macro itself does not move to its next statement until the wait ends.
Can VBA wait for milliseconds?Application.Wait is not intended as a precise millisecond timer. On Windows, the Sleep API accepts milliseconds, but it is platform-specific and still subject to operating-system scheduling.
Can I use Sleep in Excel VBA on a Mac?
Not with the kernel32 declaration shown here: that library is Windows-only. Use portable VBA logic or a Mac-specific implementation if the workbook must support both platforms.
Is DoEvents the same as waiting?
No. DoEvents yields control so queued events can be processed; it does not pause for a set duration on its own. A loop can combine it with condition checks and a timeout.
Related
- Conditional Formatting Greater Than: Excel Rules Explained
- Scatter Plot Data Sheet: How to Set Up and Read One
- How to Merge Cells in Zoho Sheet Without Losing Data
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel Macro Blocked? How to Unblock It SafelyIf Excel says a macro is blocked, first check where the workbook came from; Microsoft 365 for Windows…
- VBA Loop Through a Dictionary: Keys, Items, and ExamplesTo loop through a VBA Dictionary, use For Each key In dict.Keys, then read each value with dict(key).…
- Import Multiple Files Using VBA in Excel: A Practical GuideYes. In Excel for Microsoft 365 on Windows, VBA can loop through files in a selected folder, open…
- VBA Array Size: Practical Limits, Bounds, and Memory UseThere is no single fixed maximum size for a VBA array: its practical limit depends on available memory,…
- VBA Code to Disable Copy and Paste in ExcelTo block the usual copy-and-paste keyboard shortcuts in Excel for Microsoft 365 on Windows, use VBA’s Application.OnKey method…
- VBA MsgBox Font Size: What You Can and Cannot ChangeYou cannot set the font size of VBA’s built-in MsgBox in Excel: the function has no font-size argument…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.