How to eliminate the message "The code execution was interrupted." in VBA


When I'm running a VBA macro, eventually the code breaks, like there are breakpoints.

The message displayed is:

Code execution was interrupted.

If you accept the message and continue executing the code, the behavior is repeated if the macro is long (procedure with many lines or long loops).

The interruption happens in several places.

How can I avoid/solve this behavior?


Insert the expressions below into your code:

Application.EnableCancelKey = wdCancelDisabled

(... code ...)

Application.EnableCancelKey = wdCancelInterrupt
Scroll to Top