Code Execution Has Been Interrupted – The best fix to this Excel VBA Problem
I first came across this Microsoft Excel vba error back in 2009, when the vba dialog box interupted macro processing with the message "Code Execution Has Been Interrupted" and it quite literally did my head in.
It’s a weird error because it does not have an error number and in fact it is not really an error but rather a bug for which a lot of misinformation existed on the net back then.
The Problem defined.
You have written your Excel VBA application and everything is working fine, then for no apparent reason the following dialog box pops up, you click "Debug" on the dialog box but you cannot find anything wrong with your code.
Maybe it was a one off and you run the code again, but the message "Code Execution Has Been Interrupted" occurs again, oops!
When that happened to me, after a lot of research on the net, I thought I was up a certain creek without a paddle.
Since my application was going to be deployed to my user base, I could not have something as unprofessional as this dialog box popping up randomly.
The code would go into break mode at various parts of the program even though no "break points" or "STOP" commands existed on those lines.
What I think Causes It
I can only guess at this, not being a Microsoft Insider, but it seems to me that when you set breakpoints in your code, either by using the "STOP" command or clicking the left sidebar of the code or hitting "ctrl" + "break" to enter break mode during your development process, Microsoft Excel sometimes records this "behind the scenes" and does not clear the breakpoint out of it’s "memory".
So the breakpoint somehow gets hardcoded into your vba module within the file even though there is no visible breakpoint in your visual basic editor.
The Solution – Clear the hidden break in the code with another "Ctrl + Break"
So when this happens to you, click "Debug" on the Microsoft VBA "Code Execution Interrupted" dialog box, this will jump you to the Visual Basic Editor and a particular line of code will be highlighted to show that execution has stopped at that point.
As the compiled vba code in the workbook probably has a hidden breakpoint saved at this point, just hit "Ctrl + Break" on your keyboard (I tend to do Ctrl+Break multiple times).
This removes the hidden breakpoint and all you need to do now is save the workbook and your problem is solved, at least for that breakpoint.
If this problem does occur again, most likely you have multiple hidden breakpoints in your application.
Just rinse and repeat the above instructions for each instance of "Code Execution Interrupted" until the problem is solved.
Note do not use Application.EnableCancelKey = xlDisabled as this does not solve the problem and in fact ensures that you cannot "Break" into the application if something goes wrong.
If you found this article helpful then why not leave comment and or share it using one of the social media buttons below.