Fix for “Code execution has been interrupted” in Excel vba macros.

February 27th, 2009

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

  1. G
    Posted June 24, 2009 at 9:21 pm | Permalink

    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?

  2. ramesh
    Posted July 8, 2009 at 12:12 am | Permalink

    Hi Maheshwaran Subramaniya,

    Thanks for giving valuable suggestion

  3. Posted August 24, 2009 at 9:54 pm | Permalink

    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?

  4. ton
    Posted September 16, 2009 at 11:07 am | Permalink

    good stuff man! this error just started out of the blue. the quickfix save a lot of headache..thanks

  5. CL
    Posted January 28, 2010 at 10:09 am | Permalink

    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.

  6. optimist
    Posted April 5, 2010 at 9:45 am | Permalink

    God bless you, it solved my problems. Please convey this to mr. Vijayaragavan too

  7. RGS
    Posted May 13, 2010 at 1:58 pm | Permalink

    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.

  8. Posted May 16, 2010 at 8:41 pm | Permalink

    Great to hear that your problem got fixed

  9. Posted May 19, 2010 at 12:40 pm | Permalink

    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.

  10. Posted July 18, 2010 at 2:45 am | Permalink

    Thanks very much for sharing this tip. It solved my problem.

  11. DMHS86
    Posted July 21, 2010 at 12:34 pm | Permalink

    OH THANK YOU SO MUCH!!!! I really needed a concise answer like yours thanks! :)

  12. baffy2000
    Posted September 15, 2010 at 8:47 am | Permalink

    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.

  13. Shoki
    Posted September 30, 2010 at 2:31 am | Permalink

    FIX:

    Just hit Ctrl+Break while NOT running a macro.
    The interruptions will stop.
    Just another weird bug, i guess
    ?

  14. GrahamT
    Posted November 14, 2010 at 5:57 pm | Permalink

    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.

  15. Gangaram
    Posted December 17, 2010 at 7:15 am | Permalink

    Thanks a lot.. dude..

  16. Gulzar
    Posted January 4, 2011 at 10:54 pm | Permalink

    Great it worked for me toooooo. Thankooooo

  17. Tom
    Posted January 13, 2011 at 3:36 pm | Permalink

    Awesome. Fixed my problems too! Thanks!

  18. Sachin
    Posted January 19, 2011 at 2:19 pm | Permalink

    Thank you so much ….

  19. Jeanne
    Posted February 14, 2011 at 12:20 pm | Permalink

    Thanks very much…this worked like a charm.

  20. mugil
    Posted February 27, 2011 at 8:59 am | Permalink

    use this cmd at the start of your macro

    Application.EnableCancelKey = xlDisabled

  21. Javier Luce
    Posted March 28, 2011 at 2:19 pm | Permalink

    Thanks a lot, you have just saved me!

  22. Conor
    Posted April 11, 2011 at 10:42 am | Permalink

    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!!

  23. lomoan
    Posted April 15, 2011 at 8:46 am | Permalink

    thanks a lot bro…

  24. Posted April 26, 2011 at 10:12 am | Permalink

    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!

  25. Sandor
    Posted May 4, 2011 at 9:38 am | Permalink

    Thanks M.S.! This saved my life.

  26. michelle
    Posted May 11, 2011 at 12:40 pm | Permalink

    MANY THANKS THIS SOLVED MY WHOLE DAY

  27. Posted May 26, 2011 at 12:22 pm | Permalink

    Saved my day as well. What a pain!

  28. James
    Posted June 3, 2011 at 5:01 am | Permalink

    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.

  29. Posted June 3, 2011 at 5:03 am | Permalink

    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.

  30. Naren
    Posted June 29, 2011 at 6:18 am | Permalink

    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.

  31. John
    Posted June 30, 2011 at 12:30 pm | Permalink

    check to see if you have a duplicate “on error resume next” in your code. If you do, it may cause the interuption.

  32. K3G4
    Posted July 6, 2011 at 3:52 am | Permalink

    CTRL + BRK works! thanks for the tip

  33. Josh
    Posted July 18, 2011 at 9:19 am | Permalink

    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.

  34. JeffK
    Posted July 25, 2011 at 2:52 pm | Permalink

    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…

  35. tom
    Posted August 11, 2011 at 5:07 pm | Permalink

    Ctrl+Break fixed my problem. Thanks!

  36. chenderson
    Posted August 15, 2011 at 5:29 pm | Permalink

    Wow.. never seen this before and it seems to be a pretty obscure issue… thank you very much!

  37. Juan
    Posted September 1, 2011 at 8:20 am | Permalink

    It worked!
    Shoki and Maheshwaran Subramaniya, your tips worked!

  38. Vijay
    Posted September 12, 2011 at 3:28 pm | Permalink

    Thanks mate! this code works

  39. Karry
    Posted September 13, 2011 at 12:07 pm | Permalink

    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.

  40. s Dren
    Posted October 7, 2011 at 8:18 am | Permalink

    Some a simple and elegant fix.
    Thanks to all

  41. s Dren
    Posted October 7, 2011 at 8:25 am | Permalink

    I have been using vba since 1996.
    I was hit by the interruption msg after using it for son long

  42. Gaurav Kumar
    Posted October 18, 2011 at 5:24 am | Permalink

    Many thanks…

  43. srikanth
    Posted October 25, 2011 at 11:24 pm | Permalink

    Thanks Man…

  44. Natalia
    Posted October 31, 2011 at 12:00 am | Permalink

    God Bless You! :)

  45. Deb
    Posted October 31, 2011 at 12:17 pm | Permalink

    THANKS! CTRL-Brk while code is NOT running would solve the problem

  46. Andrew
    Posted November 8, 2011 at 6:15 pm | Permalink

    CTRL-Brk while the code is not running.
    OUTSTANDING solution!
    Thank you so much.

  47. Rob
    Posted November 9, 2011 at 4:13 pm | Permalink

    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!

  48. Jaime
    Posted November 10, 2011 at 12:30 pm | Permalink

    THANKYOU THANKYOU THANKYOU!!!!!!!!!!!!!!!:)

  49. Venkat
    Posted November 14, 2011 at 12:39 am | Permalink

    Thanks a lot man..

  50. Kazue
    Posted November 16, 2011 at 6:47 pm | Permalink

    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!!!

  51. NEX-5N
    Posted November 17, 2011 at 11:37 am | Permalink

    ????? ??????? ??????? ?????????? ?????? ??? ???????. ?? ????????? ??? ????????? ??? ??????? ????? ?? ???? ?? ????.

  52. Posted November 24, 2011 at 5:10 am | Permalink

    That working.
    But I need to add this line to each MAcro.

    Have anybody found a new finale solution?

  53. Floyd
    Posted November 30, 2011 at 1:12 pm | Permalink

    Thanks man!!! It worked!!

  54. MB1
    Posted December 5, 2011 at 6:34 am | Permalink

    CTRL-BREAK – worked a treat. Thank you!!!

  55. David
    Posted December 6, 2011 at 11:26 am | Permalink

    CTRl-BREAK worked for me too. Thank you so much.

  56. K. Satish Kumar
    Posted December 13, 2011 at 11:48 am | Permalink

    Thanks a lot VR and Corno.

  57. Abhinav Sharma
    Posted December 21, 2011 at 9:13 pm | Permalink

    Thanks a alotz dude…

  58. Posted January 2, 2012 at 2:04 am | Permalink

    thank u so very much for this article

  59. Posted January 3, 2012 at 6:07 am | Permalink

    this saved my bacon today. Why did it start happening out of the blue though?

  60. TWAINdriver
    Posted January 15, 2012 at 3:06 pm | Permalink

    @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!

Post a Comment

Your email is never shared. Required fields are marked *

*
*