Smart Systems for Home

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

Excel VBA No Wait: Skip Delays in Macro Execution

· 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

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

  1. Open Excel and press Alt + F11 to open the Visual Basic for Applications editor.
  2. In the Project Explorer, right-click your workbook name and select Insert > Module to create a new code module.
  3. Write a subroutine that calls an external process — for example, launching Notepad: Shell "notepad.exe", vbNormalFocus
  4. Immediately after the Shell command, add DoEvents to allow Excel to process other events without pausing. This prevents Excel from freezing while the external app runs.
  5. 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 by DoEvents and Application.Wait Now + TimeValue("0:00:01") if you must delay briefly, but avoid long waits.
  6. Replace any Application.Wait statements with DoEvents and a timer check using Timer for non-blocking delays. For example, set startTime = Timer and loop while Timer - startTime < 5 with DoEvents inside to keep Excel responsive.
  7. For web queries or data connections, set QueryTables.Item(1).BackgroundQuery = True before executing the query. This ensures the query runs asynchronously — the macro continues without waiting for data to load.
  8. When using GetObject or CreateObject to interact with other applications (like Word or Outlook), avoid calling their blocking methods. Instead, use events or poll for completion using object properties.
  9. Always wrap your code in error handling using On Error Resume Next and On Error GoTo 0 around external interactions to prevent crashes if the external process fails to respond.
  10. Test your macro by running it from Excel (press F5 in 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.Wait for long delays — this locks Excel completely and defeats the purpose of 'No Wait'. Use DoEvents with a timer loop instead.
  • Assuming Shell returns 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 DoEvents in 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 BackgroundQuery to False if you later need synchronous behavior — this causes inconsistent results.

Tips

  • Use Timer for 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.WinHttpRequest with .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 Shell doesn’t launch the program, verify the path is correct or use the full path like Shell "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 = True before 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. Use QueryTable from the worksheet’s QueryTables collection, 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, but Shell 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 like WaitForSingleObject, 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.