Excel VBA No Wait: Skip Delays in Macro Execution
In this article
Excel VBA 'No Wait' means preventing your macro from pausing while waiting for external processes to finish, allowing your code to continue immediately. This is crucial when automating tasks like launching external programs, waiting for file writes, or interacting with web queries that may hang or delay execution. Without proper handling, your VBA macro can freeze or behave unpredictably. You need only Microsoft Excel with VBA enabled and basic knowledge of writing macros.
What You'll Need
- Microsoft Excel 2010 or later (32-bit or 64-bit)
- VBA enabled in Excel (File > Options > Customize Ribbon > check 'Developer')
- A macro-enabled workbook (.xlsm)
- Basic understanding of VBA syntax and the Application object
Step-by-Step
- Open Excel and press
Alt + F11to open the Visual Basic for Applications editor. - In the Project Explorer, right-click your workbook name and select Insert > Module to create a new code module.
- Write a subroutine that calls an external process — for example, launching Notepad:
Shell "notepad.exe", vbNormalFocus - Immediately after the Shell command, add
DoEventsto allow Excel to process other events without pausing. This prevents Excel from freezing while the external app runs. - If you're waiting for a file to be generated by the external process, use a loop with
Dir()to check for the file's existence:Do While Dir("C:\Temp\output.txt") = ""followed byDoEventsandApplication.Wait Now + TimeValue("0:00:01")if you must delay briefly, but avoid long waits. - Replace any
Application.Waitstatements withDoEventsand a timer check usingTimerfor non-blocking delays. For example, setstartTime = Timerand loop whileTimer - startTime < 5withDoEventsinside to keep Excel responsive. - For web queries or data connections, set
QueryTables.Item(1).BackgroundQuery = Truebefore executing the query. This ensures the query runs asynchronously — the macro continues without waiting for data to load. - When using
GetObjectorCreateObjectto interact with other applications (like Word or Outlook), avoid calling their blocking methods. Instead, use events or poll for completion using object properties. - Always wrap your code in error handling using
On Error Resume NextandOn Error GoTo 0around external interactions to prevent crashes if the external process fails to respond. - Test your macro by running it from Excel (press
F5in the VBA editor or assign it to a button on the worksheet). Observe whether Excel remains responsive while the external process runs.
Common Mistakes
- Using
Application.Waitfor long delays — this locks Excel completely and defeats the purpose of 'No Wait'. UseDoEventswith a timer loop instead. - Assuming
Shellreturns a process ID that can be monitored — it does not reliably return a handle on all Windows versions. Do not rely on it for process tracking. - Not using
DoEventsin loops that check file existence or external status — this causes Excel to appear frozen. - Calling synchronous methods on COM objects (like Word.Document.Save) without setting background execution — this blocks VBA until the save completes.
- Forgetting to reset
BackgroundQuerytoFalseif you later need synchronous behavior — this causes inconsistent results.
Tips
- Use
Timerfor millisecond-accurate delays without freezing Excel. Example:Start = Timer: Do While Timer - Start < 2: DoEvents: Loop - For file monitoring, use
Dir()to check existence — it's faster and more reliable than trying to open the file. - When interacting with web services via HTTP requests, use
WinHttp.WinHttpRequestwith.Open "GET", url, True(the third parameter = True makes it asynchronous). - Always test your 'No Wait' logic on a slow machine or with a deliberately delayed process (like a 10-second batch file) to ensure responsiveness.
- Keep a log in a worksheet cell with
Cells(1,1) = Now & " - External task started"to track timing and debug delays. - If using Excel's built-in data connections, prefer Power Query over legacy QueryTables where possible — they offer better async support and error handling.
Troubleshooting
- If Excel freezes despite using
DoEvents, check for infinite loops or missing exit conditions in your timing loops. Add a counter and exit after 30 seconds to prevent hangs. - If
Shelldoesn’t launch the program, verify the path is correct or use the full path likeShell "C:\Windows\System32\notepad.exe", vbNormalFocus. - If the file you’re waiting for never appears, check if the external process has write permissions to the target folder. Run Excel as administrator if needed.
- If background queries still block execution, ensure you set
BackgroundQuery = Truebefore calling.Refresh— setting it after has no effect. - If you get a runtime error 438 (object doesn’t support property) when using
BackgroundQuery, you’re likely referencing the wrong object type. UseQueryTablefrom the worksheet’sQueryTablescollection, not a PivotTable or ListObject. - If VBA crashes when interacting with Outlook or Word, ensure those applications are not already running in a corrupted state — restart them manually before rerunning the macro.
Frequently Asked Questions
Can I completely eliminate all delays in VBA macros?
No. Some delays are unavoidable when waiting for external systems (network, hardware, file I/O). The goal is to prevent Excel from freezing while waiting, not to remove the underlying delay.Why is DoEvents not enough to prevent freezing?
DoEvents allows Excel to respond to user input and process queued events, but if your code has a long-running loop without it, Excel still locks up. Always place DoEvents inside loops that wait for external conditions.
Does this work in Excel for Mac?
Most VBA features work on Mac, butShell and file system calls behave differently. Use MacScript instead of Shell on Mac, and test file paths carefully — Mac uses POSIX paths, not Windows backslashes.
Can I use this with Power Automate or cloud triggers?
No. Power Automate runs externally and cannot be controlled by VBA's 'No Wait' techniques. Use VBA only for local automation. For cloud workflows, use Power Automate’s own async triggers.What’s the difference between Application.Wait and DoEvents?
Application.Wait pauses the entire VBA thread — Excel becomes unresponsive. DoEvents yields control briefly to the operating system, letting Excel update the UI and respond to clicks or keystrokes.
Is there a way to know when an external process finishes without polling?
Not reliably in VBA without using Windows API calls likeWaitForSingleObject, which requires advanced coding and is not recommended unless you're experienced with API declarations. Polling with Dir() or checking process lists via WMI is safer and more portable.