Why Word VBA Sub Stops Mid-Execution Without an Error Message
🔍 WiseChecker

Why Word VBA Sub Stops Mid-Execution Without an Error Message

You run a VBA macro in Word, and it stops partway through the code without showing any error. The macro simply halts, and no dialog box or debugger appears. This behavior is not a random glitch. It is caused by specific VBA settings, unhandled runtime conditions, or the way Word handles memory and object references. This article explains the root causes of silent macro termination and provides practical steps to prevent it.

Key Takeaways: Stop Word VBA Macros From Halting Silently

  • Tools > Macros > Macros > Select macro > Step Into (F8): Use step-by-step execution to identify the exact line where execution stops.
  • VBA Editor > Tools > Options > General > Break on Unhandled Errors: Enables the debugger to catch errors that otherwise cause silent termination.
  • VBA Editor > Debug > Compile VBAProject: Finds syntax and compile-time errors before the macro runs.

ADVERTISEMENT

Why a VBA Sub Stops Without an Error Dialog

Word VBA macros stop silently for three main reasons: an unhandled runtime error that does not trigger the standard error handler, a DoEvents or Application.Wait call that allows user interaction to cancel the macro, or a corrupted or missing object reference that causes Word to skip the remaining code. Each cause has a different mechanism.

Unhandled Runtime Errors With On Error Resume Next

When a macro uses On Error Resume Next, any error after that line does not show a dialog. The code continues until it hits another error that the resume statement cannot bypass. If the error occurs inside a loop or a conditional block, the macro may exit the procedure early without warning. The Err.Number property holds the error code, but if the code does not check it, the error is invisible.

DoEvents and User Cancellation

The DoEvents function yields execution to the operating system so that the user can interact with Word. If the user presses Escape or clicks a button that interrupts the macro, Word may terminate the sub without an error message. Similarly, Application.Wait pauses execution but does not protect against user cancellation.

Object Reference Loss

If a macro sets an object variable to Nothing or if Word releases the object due to a failed method call, subsequent lines that reference that object cause a silent failure. Word does not always raise a trappable error for Object variable or With block variable not set in every context. The macro stops at the line that tries to use the invalid object.

Steps to Identify and Fix Silent Macro Stops

Step Through the Macro Line by Line

  1. Open the VBA Editor
    Press Alt+F11 in Word to open the Visual Basic Editor. Locate the module that contains the stopping macro in the Project Explorer pane.
  2. Set a breakpoint at the start
    Click in the left margin next to the first executable line of the Sub. A red dot appears. The macro will pause before running that line.
  3. Run the macro and press F8 repeatedly
    Press F8 to execute one line at a time. Watch the yellow highlight. When the highlight disappears and the editor returns to normal, that is the line where execution stopped. Note the line number and the code.

Enable Break on Unhandled Errors

  1. Open VBA Editor options
    In the VBA Editor, go to Tools > Options. Click the General tab.
  2. Select Break on Unhandled Errors
    Under Error Trapping, choose Break on Unhandled Errors. Click OK. This setting forces the debugger to stop on any error that is not caught by an On Error statement.
  3. Run the macro again
    Press F5 to run the macro. If an error occurs, the debugger now shows the line and the error description.

Compile the VBA Project

  1. Open the VBA Editor
    Press Alt+F11.
  2. Run Compile VBAProject
    Go to Debug > Compile VBAProject. The editor checks all modules for syntax errors, undeclared variables (if Option Explicit is set), and type mismatches. If a compile error appears, fix it and compile again until no errors are reported.

Check for On Error Resume Next Without Error Handling

  1. Search the code for On Error Resume Next
    Press Ctrl+F in the VBA Editor and search for On Error Resume Next. Examine each occurrence.
  2. Add error checking after risky operations
    After each line that could fail, insert If Err.Number <> 0 Then to log or handle the error. Example:
    On Error Resume Next
    Selection.TypeText Text:=someVariable
    If Err.Number <> 0 Then
       Debug.Print "Error " & Err.Number & ": " & Err.Description
       Err.Clear
    End If

Remove DoEvents Inside Loops

  1. Locate DoEvents calls
    Press Ctrl+F and search for DoEvents. If the macro contains DoEvents inside a loop, comment it out by adding a single quote at the start of the line.
  2. Replace with Application.StatusBar updates
    Instead of DoEvents, use Application.StatusBar = "Processing item " & i to give feedback without yielding control to the user.

Verify Object Variables Are Not Nothing

  1. Add explicit checks before using objects
    Before calling a method or property on an object variable, insert If Not objVar Is Nothing Then. Example:
    Dim doc As Document
    Set doc = Documents.Open("C:\test.docx")
    If Not doc Is Nothing Then
       doc.SaveAs2 "C:\test2.docx"
    End If

ADVERTISEMENT

If the Macro Still Stops After the Main Fixes

Word Freezes or Hangs During a Long-Running Macro

A macro that loops through hundreds of paragraphs or tables can exhaust Word’s internal memory. Word may stop executing the sub without an error and become unresponsive. To fix this, add Application.ScreenUpdating = False at the start of the macro and set it back to True at the end. Also reduce the number of Selection objects by using direct Range objects instead.

Protected View Blocks the Document Object

If the macro opens a document from an email attachment or a network share, Word opens it in Protected View. The Document object is read-only, and any attempt to modify it causes a silent failure. Use Documents.Open FileName:=path, ReadOnly:=False and check the Document.ProtectedViewWindow property. If the document is in Protected View, enable editing via ActiveProtectedViewWindow.Edit before running the macro.

Add-In Conflicts Cause Early Termination

Third-party add-ins can intercept VBA execution and stop a sub. To test, start Word in safe mode: press the Windows key + R, type winword /safe, and press Enter. Run the macro. If it completes without stopping, disable add-ins one by one in File > Options > Add-Ins > Manage COM Add-ins.

Item Silent Stop (no error dialog) Error Dialog (with debug option)
On Error Resume Next active Yes, error is suppressed No
Break on Unhandled Errors setting Disabled Enabled
DoEvents or Application.Wait used Yes, user can cancel No
Object variable set to Nothing Yes, code halts on next line Sometimes, depends on context

Now you can diagnose why a Word VBA sub stops mid-execution without an error message. First, enable Break on Unhandled Errors in the VBA Editor options. Then step through the macro with F8 to locate the failing line. Check for On Error Resume Next without error handling and replace DoEvents with status bar updates. For advanced debugging, use the Immediate pane to print Err.Number after each suspected line. This approach eliminates guesswork and gives you full control over macro execution.

ADVERTISEMENT