In excel, while executing macros you may get the error message “code execution has been interrupted”. Generally this error message should appear only if you hit “Ctrl +Break” to stop the execution and view the code. But there may be certain instances, where you may get this error message even without pressing “Ctrl + Break”. If you hit “Continue” button, the code will execute for a while but again you may get the same error message. At one point of time, you may need to click “continue” button many times to execute a macro. There may be plent of reasons behind it like new software installation, key settings etc..
Problem Solution:
The solution for this problem is to add the line of code “Application.EnableCancelKey = xlDisabled” in the first line of your macro.. This will fix the problem and you will be able to execute the macro successfully without getting the error message “Code execution has been interrupted”.
Thanks: This tip is given by one of my collegue Vijayaragavan..
60 Comments
So how do I fix this without disabling the “ESC” key to halt the code?
This is a workaround, just like exporting the modules, restarting and reimporting the modules.
Where is the patch on this, Microsoft?
Hi Maheshwaran Subramaniya,
Thanks for giving valuable suggestion
God bless you! This was driving me absolutely nuts. The weird thing is that the code was working fine and then all of a sudden I started seeing the code interruption dialogs. Any idea what it is that causes this to happen to code that was once working that no longer works?
good stuff man! this error just started out of the blue. the quickfix save a lot of headache..thanks
I’d love to say this solved my Excel 2007 vba issue, but only a reboot seems to prevent the message from popping up for a while, until I’ve been editing the vba code (run and test, ctrl-break) spreadsheet enough to cause the problem to start occurring again.
God bless you, it solved my problems. Please convey this to mr. Vijayaragavan too
Like others have stated, this started out of nowhere. At work, we have been using one of our macros since 2007. No problems until the middle of April, 2010 when it suddenly went haywire. Thanks for the code fix. It appears to have resolved the code interuption issue.
Great to hear that your problem got fixed
Hi sir,
Could you please share me the code of Comments.php. I am using the Forte theme but my comment section doesn’t work and I don’t know how to fix it.
Thanks in advance.
Thanks very much for sharing this tip. It solved my problem.
OH THANK YOU SO MUCH!!!! I really needed a concise answer like yours thanks!
I just had this problem, and found this solution, and for some reason it reminded me of a weird (read: extremely weird) bug in Visual Studio.
In any case, I was having this Excel problem, couldn’t stop this happening, so I clicked CTRL-BRK. Not while I was running the code, just with the editor open. I then ran it again and, hey presto, no problem.
If you think this is weird, the Visual Studio bug is even weirder. Sometimes, the “find in files” command does not work. When this happens, simply click CTRL-BRK (or CTRL-ScrollLock) and it works again.
Anyway, it would seem this is an IDE problem, not a code problem. If you do this (and it works for you), you will need no workarounds in your code.
FIX:
Just hit Ctrl+Break while NOT running a macro.
The interruptions will stop.
Just another weird bug, i guess
?
Shoki, that fixed it for me. Must be some flag lurking somewhere (only interrupted after macro running for ~15 seconds so not impacting most tasks).
Many Thanks.
Thanks a lot.. dude..
Great it worked for me toooooo. Thankooooo
Awesome. Fixed my problems too! Thanks!
Thank you so much ….
Thanks very much…this worked like a charm.
use this cmd at the start of your macro
Application.EnableCancelKey = xlDisabled
Thanks a lot, you have just saved me!
Picked up a really good tip on solving this one. When the box comes up, hit debug then hit Ctrl-Break. This should clear the condition without reboots or resetting EnableCancelKey. Worked for me anyway!!
thanks a lot bro…
Thank you Conor for your solution!
In the debug window press Control+Break and this fixes the problem.
In the Excel window press Control+Break and the problem comes again!
Microsoft have to fix this asap!
Thanks M.S.! This saved my life.
MANY THANKS THIS SOLVED MY WHOLE DAY
Saved my day as well. What a pain!
This bug has plagued me for 6 years of VBA development. I’m here after almost 12 months of not seeing this error through a slightly different approach:
I removed the page break key from Keyboard. This worked great until I basically forgot how utterly frustrating it is when it happens to a giant project. Like it has now, rather close to a deadline.
Trying to debug large modules without the page break key key is an extremely masochistic process, and such I have decided VBA now needs to be relegated to the history books along with Fortran and Mayan Hieroglyphs.
Anyone considering devoping VBA skills can save themselves some time and cut themselves instead.
This bug has plagued me for 6 years of VBA development. I’m here after almost 12 months of not seeing this error through a slightly different approach:
I removed the page break key from Keyboard. This worked great until I basically forgot how utterly frustrating it is when it happens to a giant project. Like it has now, rather close to a deadline.
Trying to debug large modules without the page break key key is an extremely masochistic process, and such I have decided VBA now needs to be relegated to the history books along with Fortran and Mayan Hieroglyphs.
Anyone considering devoping VBA skills can save themselves some time and cut themselves instead.
But the Problem is once if we use “Application.EnableCancelKey = xlDisabled” in our code and when we want to break it while the code is running using Ctrl+Break, it is not getting stopped. we are unable to stop the macro while it is running. Can anyone help me on it.
Thanks in advance.
Naren.
check to see if you have a duplicate “on error resume next” in your code. If you do, it may cause the interuption.
CTRL + BRK works! thanks for the tip
What a bizarre problem. Been working with VBA for 10 years and never had this before today. Who would think doing CTRL-Brk while code is NOT running would solve the problem. Thanks to the users that suggested that! My only concern now is this may happen on users machines down the road.
Disabling code break is not a good option, in my opinion, despite the effectiveness in this case. /Sigh. Good going Microsoft.
Has anyone thought that this bug may be caused by a sticking “Esc” or “Break” key? This may be why hitting the key again may fix the problem. Just wondering…
Ctrl+Break fixed my problem. Thanks!
Wow.. never seen this before and it seems to be a pretty obscure issue… thank you very much!
It worked!
Shoki and Maheshwaran Subramaniya, your tips worked!
Thanks mate! this code works
Sometimes Ctrl+Break doesn’t fix, but I’ve found if you wait until the code stops executing, then click debug, then shift+Ctrl+break, this sometimes fixes it.
Some a simple and elegant fix.
Thanks to all
I have been using vba since 1996.
I was hit by the interruption msg after using it for son long
Many thanks…
Thanks Man…
God Bless You!
THANKS! CTRL-Brk while code is NOT running would solve the problem
CTRL-Brk while the code is not running.
OUTSTANDING solution!
Thank you so much.
Just starting seeing this ridiculous error message after doing some minor mods to my code. I was really starting to stress figuring this would be next to impossible to actually fix. THANKS SO MUCH!! Your one simple line of code worked like a charm and saved me MANY hours of debug, I’m sure!
THANKYOU THANKYOU THANKYOU!!!!!!!!!!!!!!!:)
Thanks a lot man..
It worked! Thanks so much for an easy fix to a very puzzling thing. I figured I must have hit some combination key by mistake, as this started out of the clear blue for me, as well, but I had no idea how to fix it. I am not a programmer and have limited knowledge of code but use a ton of macros in my work. In searching the Internet, I was surprised to find so many others had experienced the same thing but with no solutions offered until I found this site. Thanks again!!!
????? ??????? ??????? ?????????? ?????? ??? ???????. ?? ????????? ??? ????????? ??? ??????? ????? ?? ???? ?? ????.
That working.
But I need to add this line to each MAcro.
Have anybody found a new finale solution?
Thanks man!!! It worked!!
CTRL-BREAK – worked a treat. Thank you!!!
CTRl-BREAK worked for me too. Thank you so much.
Thanks a lot VR and Corno.
Thanks a alotz dude…
thank u so very much for this article
this saved my bacon today. Why did it start happening out of the blue though?
@baffy2000: Hitting CTRL+BREAK in the VB Editor while not executing code fixed my problem. This fix has worked for me on several occasions with Excel 2010 workbooks. Thanks so much!