Excel VBA: How to Wait 10 Seconds (Pause Macro)
In this article
To make Excel VBA wait 10 seconds, use Application.Wait Now + TimeValue("00:00:10"). This pauses the macro for exactly ten seconds, freezing Excel and ignoring keyboard and mouse input until the time has elapsed. For a non-freezing alternative, call the Windows Sleep API with 10000 milliseconds, or use a loop with DoEvents if you need Excel to stay responsive. The Application.Wait method is the simplest and works on both Windows and Mac; the Sleep API is Windows-only.
What You'll Need
- Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer).
- A macro-enabled workbook (.xlsm) or an existing workbook where you can add a module.
- Basic familiarity with the VBA editor (Alt+F11).
- For the Sleep API method: a Windows PC (the API is not available on Mac).
Step-by-Step
- Open the VBA editor. Press Alt+F11 (on Mac, Fn+Alt+F11). The editor opens in a separate window.
- Insert a module. In the Project Explorer, right-click your workbook name, choose Insert > Module. A blank code window appears.
- Write the basic Wait statement. Type the following into the module:
TheSub WaitTenSeconds() Application.Wait Now + TimeValue("00:00:10") MsgBox "Done waiting" End SubTimeValue("00:00:10")creates a time serial for 10 seconds.Nowreturns the current date and time, so adding them gives a moment 10 seconds in the future.Application.Waitpauses until that moment. - Run the macro. Press F5 while the cursor is inside the subroutine, or go back to Excel and use Developer > Macros, select
WaitTenSeconds, and click Run. Excel will appear frozen for 10 seconds, then show the message box. - Test the non-freezing alternative (optional). If you need Excel to remain responsive (for example, to let the user cancel or to allow other macros to run), add this at the top of the module, above any procedures:
Then write a second subroutine:#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 IfSub SleepTenSeconds() Sleep 10000 MsgBox "Done sleeping" End SubSleeptakes milliseconds, so 10000 = 10 seconds. This also freezes Excel's interface, but it does not process messages, so it is slightly more efficient thanApplication.Waitin some cases. Note:Sleepis Windows-only. - Use a DoEvents loop for a responsive wait (optional). If you want Excel to stay interactive, use a loop that checks the time and calls
DoEvents:
This lets Excel process other events (like button clicks) during the wait, but it is less precise and can be interrupted by other code. Use it only when responsiveness matters.Sub ResponsiveWait() Dim startTime As Double startTime = Timer Do While Timer < startTime + 10 DoEvents Loop MsgBox "Done" End Sub - Save your work. Press Ctrl+S. If prompted to save as macro-enabled, choose Yes and keep the .xlsm format.
Common Mistakes
- Using
Wait 10instead ofApplication.Wait.Waitis not a standalone VBA statement; it must be called asApplication.Waitwith a time value, not a number of seconds. - Passing seconds directly.
Application.Wait 10will cause a type mismatch error becauseWaitexpects a date/time serial, not an integer. Always useNow + TimeValue("00:00:10"). - Forgetting
PtrSafein 64-bit Office. If you use theSleepAPI withoutPtrSafein a 64-bit installation, you get a compile error. The conditional compilation block above handles both 32-bit and 64-bit. - Assuming
Sleepworks on Mac. The Windows API declaration will fail on macOS. UseApplication.Waitfor cross-platform code. - Expecting
Application.Waitto be precise to the millisecond. It is accurate to about one second, and system load can extend the wait slightly. - Using
DoEventswithout a time check. A loop that only callsDoEventswill run forever and lock up Excel. Always include a time condition.
Tips
- To wait a different number of seconds, change the
TimeValuestring. For example,TimeValue("00:00:05")waits 5 seconds,TimeValue("00:01:00")waits 1 minute. - You can combine
Application.WaitwithDoEventsto keep the screen updating: callDoEventsimmediately beforeApplication.Waitso any pending screen refreshes happen first. - If you need to wait until a specific clock time (e.g., 10:00 AM), use
Application.Wait TimeValue("10:00:00")but be aware it waits until that time on the current day; if the time has passed, it waits until the next day. - For long waits, consider breaking the wait into shorter intervals with
DoEventsso users can cancel or see progress. - Always test macros in a copy of your workbook before running them on important data.
Troubleshooting
- Compile error: Sub or Function not defined. You likely typed
WaitwithoutApplication.. Change toApplication.Wait. - Run-time error '13': Type mismatch. You passed a number to
Application.Waitinstead of a time value. UseNow + TimeValue("00:00:10"). - Macro runs but does not pause. Check that the line is actually executed (use F8 to step through). Also ensure the system clock is correct;
Application.Waitrelies on the system time. - Excel becomes unresponsive and never recovers. If you used an infinite loop with
DoEvents, press Ctrl+Break to interrupt. If that fails, close Excel via Task Manager (you may lose unsaved changes). - Sleep API causes "Can't find DLL entry point" or similar. Ensure the declaration is exactly as shown and that you are on Windows. On 64-bit Office, the
PtrSafekeyword is required. - Wait time seems longer than expected. Other macros or system load can delay the resume. For critical timing, use a loop with
Timerand check elapsed time.
Frequently Asked Questions
Can I make Excel VBA wait less than a second?
Application.Wait has a resolution of about one second, so it cannot reliably wait less than that. For sub-second delays, use the Sleep API with milliseconds (e.g., Sleep 500 for half a second) on Windows, or a tight loop with Timer for cross-platform code.
Does Application.Wait work on Mac?
Yes, Application.Wait works in Excel for Mac. The Sleep API does not, because it is a Windows system call.
Why does Excel freeze during the wait?
Both Application.Wait and Sleep block the main thread, so Excel cannot respond to input. If you need responsiveness, use a DoEvents loop, but be aware it is less precise and can allow other macros to run.
Can I cancel a wait?
With Application.Wait or Sleep, you cannot cancel except by interrupting with Ctrl+Break (which may not work during Sleep) or ending the process. A DoEvents loop can check for a cancel flag or key press.
Is there a built-in VBA function for waiting?
VBA has no native Wait function. You must use Application.Wait (Excel-specific) or the Windows Sleep API, or build a loop.
What is the maximum wait time?
Application.Wait accepts any future date/time, so you can wait for days if needed, but it is not recommended for long periods because Excel is unusable. For long waits, consider scheduling the macro to run later instead.