Code Execution Has Been Interrupted – The best fix to this Excel VBA Problem

The Problem defined.

You’ve written your Excel VBA application and everything’s 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.

Code Execution Has Been Interrupted

Maybe it’s a one off and you run the code again, but the message “Code Execution Has Been Interrupted” appears 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 couldn’t 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.

Disclosure:- If you buy this or any book using this link (at the moment only). Amazon may give me a small commission (at no extra cost to you). And if you do get one, many thanks.

Code execution has been interrupted

by whom?

not me!

I had this issue a couple of weeks ago, but for some reason (possibly an update) it seems to have stopped.

As my code was running, for no apparent reason this dialog kept popping up. It seemed especially prelavent when writing data to cells. In the end I had to wrap all my writes with

   ‘Application.EnableCancelKey = xlDisabled
   wsLogging.Cells(m_outrow, col).Value = wsLogging.Cells(m_outrow, col).Value & ” | ” & message
   ‘Application.EnableCancelKey = xlInterrupt

Anyone else bothered by this? I was going to try cleaning the code, but now it seems to have gone away. Or possibly it was someone elses code, and/or some interference from another addin? Whatever, I can’t seem to repro the behavior anymore.

If it makes any difference I am using a multilingual Office (2007 –  12.0.6550.5004).

so I am curious, did anyone else see this problem? did you work out what caused it? did you find a better workaround? has it fixed itself?



This entry was posted on Thursday, 23rd June, 2011 at 5:10 pm and is filed under development, error, Excel. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

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 doesn’t clear the breakpoint out of it’s “memory”.

So the breakpoint somehow gets hardcoded into your vba module within the file even though there’s no visible breakpoint in your visual basic editor.

Sign up below and get notified when new Business Programmer blog or video tutorials are created.

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’ve 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 doesn’t 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 leave comment and or share it using one of the social media buttons below.

( 1 оценка, среднее 5 из 5 )
Загрузка ...