Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA: How to Wait 10 Seconds (Pause Macro)

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Open the VBA editor. Press Alt+F11 (on Mac, Fn+Alt+F11). The editor opens in a separate window.
  2. Insert a module. In the Project Explorer, right-click your workbook name, choose Insert > Module. A blank code window appears.
  3. Write the basic Wait statement. Type the following into the module:
    Sub WaitTenSeconds()
        Application.Wait Now + TimeValue("00:00:10")
        MsgBox "Done waiting"
    End Sub
    The TimeValue("00:00:10") creates a time serial for 10 seconds. Now returns the current date and time, so adding them gives a moment 10 seconds in the future. Application.Wait pauses until that moment.
  4. 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.
  5. 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:
    #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
    Then write a second subroutine:
    Sub SleepTenSeconds()
        Sleep 10000
        MsgBox "Done sleeping"
    End Sub
    Sleep takes milliseconds, so 10000 = 10 seconds. This also freezes Excel's interface, but it does not process messages, so it is slightly more efficient than Application.Wait in some cases. Note: Sleep is Windows-only.
  6. 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:
    Sub ResponsiveWait()
        Dim startTime As Double
        startTime = Timer
        Do While Timer < startTime + 10
            DoEvents
        Loop
        MsgBox "Done"
    End Sub
    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.
  7. Save your work. Press Ctrl+S. If prompted to save as macro-enabled, choose Yes and keep the .xlsm format.

Common Mistakes

  • Using Wait 10 instead of Application.Wait. Wait is not a standalone VBA statement; it must be called as Application.Wait with a time value, not a number of seconds.
  • Passing seconds directly. Application.Wait 10 will cause a type mismatch error because Wait expects a date/time serial, not an integer. Always use Now + TimeValue("00:00:10").
  • Forgetting PtrSafe in 64-bit Office. If you use the Sleep API without PtrSafe in a 64-bit installation, you get a compile error. The conditional compilation block above handles both 32-bit and 64-bit.
  • Assuming Sleep works on Mac. The Windows API declaration will fail on macOS. Use Application.Wait for cross-platform code.
  • Expecting Application.Wait to be precise to the millisecond. It is accurate to about one second, and system load can extend the wait slightly.
  • Using DoEvents without a time check. A loop that only calls DoEvents will run forever and lock up Excel. Always include a time condition.

Tips

  • To wait a different number of seconds, change the TimeValue string. For example, TimeValue("00:00:05") waits 5 seconds, TimeValue("00:01:00") waits 1 minute.
  • You can combine Application.Wait with DoEvents to keep the screen updating: call DoEvents immediately before Application.Wait so 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 DoEvents so 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 Wait without Application.. Change to Application.Wait.
  • Run-time error '13': Type mismatch. You passed a number to Application.Wait instead of a time value. Use Now + 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.Wait relies 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 PtrSafe keyword is required.
  • Wait time seems longer than expected. Other macros or system load can delay the resume. For critical timing, use a loop with Timer and 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.