Name already in use
VBA-Docs / Language / Reference / User-Interface-Help / code-execution-has-been-interrupted.md
- Go to file T
- Go to line L
- Copy path
- Copy permalink
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
Code execution has been interrupted
Code execution can be suspended when necessary. This condition has the following cause and solution:
- A CTRL+BREAK (Microsoft Windows), ESC (Microsoft Excel) or COMMAND+PERIOD (Macintosh) key combination has been encountered. In the error dialog box, click Debug to enter break mode, Continue to resume, or End to stop execution.
For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).
Footer
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Excel VBA App stops spontaneously with message "Code execution has been halted"
From what I can see on the web, this is a fairly common complaint, but answers seem to be rarer. The problem is this:
We have a number of Excel VBA apps which work perfectly on a number of users’ machines. However on one machine they stop on certain lines of code. It is always the same lines, but those lines seem to have nothing in common with one another.
If you press F5 (run) after the halt, the app continues, so it’s almost like a break point has been added. We’ve tried selecting ‘remove all breaks’ from the menu and even adding a break and removing it again.
We’ve had this issue with single apps before and we’ve ‘bodged’ it by cutting code out of modules, compiling and then pasting it back in etc.
The problem now seems to relate to Excel itself rather than a single .xls, so we’re a little unsure how to manage this.
12 Answers 12
I have found a 2nd solution.
- Press "Debug" button in the popup.
- Press Ctrl + Pause|Break twice.
- Hit the play button to continue.
- Save the file after completion.
One solution is here:
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”.
But, after I inserted this line of code, I was not able to use Ctrl+Break any more. So it works but not greatly.
This problem comes from a strange quirk within Office/Windows.
After developing the same piece of VBA code and running it hundreds of times (literally) over the last couple days I ran into this problem just now. The only thing that has been different is that just prior to experiencing this perplexing problem I accidentally ended the execution of the VBA code with an unorthodox method.
I cleaned out all temp files, rebooted, etc. When I ran the code again after all of this I still got the issue — before I entered the first loop. It makes sense that «press «Debug» button in the popup, then press twice [Ctrl+Break] and after this can continue without stops» because something in the combination of Office/Windows has not released the execution. It is stuck.
The redundant Ctrl+Break action probably resolves the lingering execution.
I found hitting ctrl+break while the macro wasn’t running fixed the problem.
I would try the usual remedial things: — Run Rob Bovey’s VBA Code Cleaner on your VBA Code — remove all addins on the users PC, particularly COM and .NET addins — Delete all the users .EXD files (MSoft Update incompatibilities) — Run Excel Detect & Repair on the users system — check the size of the user’s .xlb file (should be 20-30K) — Reboot then delete all the users Temp files
I have came across this issue few times during the development of one complex Excel VBA app. Sometimes Excel started to break VBA object quite randomly. And the only remedy was to reboot machine. After reboot, Excel usually started to act normally.
Soon I have found out that possible solution to this issue is to hit CTRL+Break once when macro is NOT running. Maybe this can help to you too.
Thanks to everyone for their input. This problem got solved by choosing REPAIR in Control Panel. I guess this explicitly re-registers some of Office’s native COM components and does stuff that REINSTALL doesn’t. I expect the latter just goes through a checklist and sometimes accepts what’s there if it’s already installed, maybe. I then had a separate issue with registering my own .NET dll for COM interop on the user’s machine (despite this also working on other machines) though I think this was my error rather than Microsoft. Thanks again, I really appreciate it.
![]()
I have had this problem also using excel 2007 with a foobar.xlsm (macro enabled ) workbook which would get the «Code execution has been interrupted» by simply trying to close the workbook on the red X in the right corner with no macros running at all, or any «initialize» form, workbook, or workheet macros either. The options I got were «End» or «Continue», Debug was always greyed out. I did as a previous poster suggested Control Panel->Programs and Features-> right click «Microsoft Office Proffesional 2007» (in my case) ->change->repair.
This resolved the problem for me. I might add this happened soon after a MS update and I also found an addin in Excel called «Team Foundation» from Microsoft which I certainly didnt install voluntarily
I would like to add more details to Stan’s answer #2 for below reasons:
I faced this issue myself more than dozen times and depending on project conditions, I chose between stan’s voodoo magic answer #1 or #2. When I kept on facing it again, I become more inquistive that why it happens in first place.
I’d like to add answer for Mac users too.
There are limitations with both these possible answers:
- if the code is protected (and you don’t know password) then answer #1 won’t help.
- if the code is unprotected then answer #2 won’t let you debug the code.
It may happen due to any of the below reasons:
Operating system not allocating system resources to the Excel process. (Solution: One needs to just start the operating system — success rate is very low but has known to work many times)
P-code is the intermediate code that was used in Visual Basic (before .NET) and hence it is still used in the VBA. It enabled a more compact executable at the expense of slower execution. Why I am talking about p-code? Because it gets corrupted sometimes between multiple executions and large files or just due to installation of the software (Excel) went corrupt somewhere. When p-code corrupts. the code execution keeps getting interrupted. Solution: In these cases, it is assumed that your code has started to corrupt and chances in future are that your Excel workbook also get corrupt giving you messages like «excel file corrupted and cannot be opened». Hence, as a quick solution, you can rely on answer #1 or answer #2 as per your requirements. However, never ignore the signs of corruption. It’s better to copy your code modules in notepad, delete the modules, save & close the workbook, close the excel. Now, re-open the workbook and start creating new modules with the code copied earlier to notepad.
Mac users, try any of the below option and of them will definitely work depending on your system architecture i.e. OS and Office version
- Ctrl + Pause
- Ctrl + ScrLk
- Esc + Esc (Press twice consecutively)
You will be put into break mode using the above key combinations as the macro suspends execution immediately finishing the current task. This is replacement of Step 2.
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 interrupted 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 doesn’t have an error number and in fact it isn’t really an error but rather a bug for which a lot of misinformation existed on the net back then.
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.
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.
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.
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’ll 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).
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 this article stopped you pulling your hair out, then consider buying me a coffee below, it helps to pay for this site, and if you’re one of those good guys many thanks!
Reader Interactions
Comments
Geoff Mitchell says
This seems to work. Thanks
Sean Johnson says
Glad I could help.
White Geared says
Silly bug but thanks a lot for saving me headache.
Thank you very much. It really helps! You are a Great Guru!
How do you succeed to find out this solution?
Tanks for this simple solution. This problem still ocuurs in excel vba 2016 Dutch version.
Greg Moran says
This worked for me – thank you!
Worked for me. Thank you
Yes, It worked for me.
Thank you so much
Hema Packiriswamy says
Thanks
It worked for me
Sean Johnson says
Thanks Hema, Dev, Adam and Greg for the reply.
Glad to know that this article is useful.
It worked for me too.
Thank you
SHORT AND PROFESSIONAL.
Thanks a lot.
Imran Khan says
very nice article wonderful
Gulam M Shoeb says
Thanks Sean! This was a great help.
Sean Johnson says
Glad I could help, Gulam.
It caused me a lot of pain, back in the day.
Thanks a lot, Sean! This trick solved the problem instantly.
I agree that intervention such as the code “Application.EnableCancelKey = xlDisabled” is over doing it a bit.
Minimal solutions work the best.
holy cow! i’ve been looking for an answer to this pesky problem. this made my day. thanks so much Sean!
Sean Johnson says
I know how you feel, it totally ruined my month back in the day.
I was pulling my hair out, thank you for saving me a lot of work.
Whaaawww! This is great! Till now I had to reboot to get rid of this message. Thanks a lot.
Thank you, this worked for me. Solved!
Excellent solution, and good point about misinformation around this issue. Excel is not my forte’ but I could lend a hand if you need any database queries written
Worked like a charm. Thank You
Thank you, worked great
Great, Good solution, this is what I was looking for.
Solution seeker says
Hi this is Yaried I’ve an excel template constructed with vba program, and it works only in registered computers, this means it automatically closes when someone tries to open in unregistered computer. But I’ve suffered a problem, that they open it with applying ctrl + break to terminate auto execution. Is there some one to help with this problem
Worked efficiently. Thanks
THANK YOU – I can’t believe there are bugs like this still hanging around .
It’s working now. Maybe Compile VBAProject would have fixed it. Too late for me to check, it’s already working now.
Coffee / Beer on me if you’re anywhere near St Pauls !
if the issue comes back over and over again try to set the application.calculation to xlcalculationmanual at the beginning of the line then set back to automatic to the last line of the code. I dont know how to explain this but it works.
Worked, Thx again.
THANKS A LOT. it works for me
You saved my life, thanks for sharing the solution to this weird mystery show stopper!
Thanks for this info
This solution worked as charm thank you
Hi Sean,
That work for me too. Thanks a lot.
But I do not know how the hidden break point was added into my code since the last time everything work well. Could you or anyone tell me the reason then I can avoid next time?
Thanks,
Thank YOU! – I had just a small panic attack as I was ready to deploy when this popped up!
A question here, if it’s something related to the breakpoints previously used in the vba environnement it shouldn’t be enought to copy the code and paste it in a new workbook to bypass the problem?
I’ve done that but the problem persists… any idea?
It´s a perfect article and it works. Thank you so much.
Just had to use this while up against a deadline. Thank you.
Serdar Yalçın says
Thank you very much. It works like a charm.
Thank you. I have battling this problem for some time now. Restarting Excel never did the trick so I always ended up rebooting.
Thanks, its excellent. have problem: excel memory increase and going maximum level in memory, how to reduce or refresh it !!
Yes, this worked and was a huge help. Thank you very much!
OR open VBA editor, select ->debug->clear all breakpoints.
Wilfredo Colon says
Excelent, this work for me. Thx
You ledgend Sean.
I just had this exact problem at the end of an important production and I thought “WHAT!”
Will add that I had made a stupid error just beforehand where I forgot to reset a loop counter so crashed my code – I suppose that excel couldn’t clear the breakpoints on the recovered file.
Anyway thank you for bothering to share this online. It would have been very distressing to have my code constantly interrupted by the debugger.
Mufaddal Chittalwala says
Thank you so much Sean Johnson for this information.
I had made a macro couple of weeks back (I am still learning to create macros) tested and was working fine
In the start of this week I thought of just re-checking it to take some reference from it to write a new macro code and suddenly it started giving errors. I was confused why properly tested code giving errors and I thought I made some mistakes in the line and started trouble shooting the code instead of looking for why I was getting interrupted error. And sometimes the macro used to stop any random line which was more frustrating because the code never used to stop at the same line it used to be any random lines
From last 1 week I have been searching like crazy and changed my code so many times to make it work and couldn’t find the solution.
Finally your resolution helped and my code is running perfectly now. I just did Ctrl + Break 10-15 times as you suggested and now all problems resolved thanks to you.
Please let me know if you can help me get the complete start to end book of learning macro or videos that will be really helpful I am still learning but the video I have seems doesn’t have such trouble shooting tips
Thank you so much
Cheers,
I spent hours trying to solve this one.
Chris Hartnell says
Thanks for the solution. It was interesting, yesterday I had that happen in the code of my spreadsheet. Today I opened another spreadsheeet and the same thing happened. So its not just limited to the spreadsheet that it first happened in. It looks like Excel is carrying that into all the spreadsheets until the magical CTRL-Break method fixes it for all!
Sean Johnson says
Glad I could help
So happy I found this page instantly when searching. Can see where I could have spent many, many frustrating hours / days finding such / debugging
Sean, thanks a lot for your advice.
I was thinking there is an error in my code, but it was a bug as you explained.
Code execution has been interrupted vba как убрать
![]()
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
One of my coworker keeps getting "code execution has been interrupted" when he opens excel that contains macro.
It seems to me that it only happens on computers that have excel 2007 installed. The same spreadsheet runs perfectly on my computer whhich has Excel 2000 installed, so I assume its a problem with my settings somewhere.
I googled around and can’t seem to get a sure answer. Does anyone have any suggestions?
Answers
I have the same problem with macros in Word. With Word 2007 there was much simpler solution than restarting computer: just lockig the computer and then unlocking. Now, with Word 2010 this trick doesn’t help — I must logoff and thne login to the computer.
But it’s only workaround, the problem is still in VBE.
After some googling I’ve found better (quicker) solution: just end macro, switch to the VBE and hit Ctrl+Break. After that the code execution doesn’t break.
Boris Lehečka (Word, Access, VBA, XML, C#, SQL)
- Marked as answer by danishani Tuesday, January 31, 2012 12:51 AM
- Marked as answer by danishani Tuesday, January 31, 2012 12:51 AM
All replies
I’m having the same issue, this is disappointing and frustrating to get that popup without any reason. Can anybody help us please? this kind of things don’t suppose to happen if we are "upgrading" for an "improved" ms office.
My guess (not tested) is the macro security is set too high. meaning it doesn’t allow macros to run.
In 2003, the option is under Tools | Options | Security Tab | Macro Security button. Set the security to Medium which will prompt you enable or disable macros.
Hope this helps,
This worked for me. thanks !
It did not for me. This is extremly anoying. I have all security/privacy options set to the lowest and that thing happens randomly. In most cases it starts when I uinterupt the macro to go to the debug mode.
Could you please explain it in a more elaborate way? exactly what is happen when you open the execl which contains macro?
reading your mail whatever i have understand is that when you save it , macro was in break mode. So when ever you open it in frist go it gives you a prompt that your " code execution has been interrupted".
what you can do is open the code window "Click on Break button" and then save the workbook .Close and open it again. I believe your problem will be sloved?
- Proposed as answer by DianaSAllen Thursday, October 9, 2014 2:56 PM
I know Excel and VBA like the back of my hand and I can tell you that this one bug is the most persistant, annoying, and least addressed of all the Excel bugs one could possibly encounter. It starts after pressing ctrl+break once, then after the VBA editor goes into break mode almost at random. Also, If you happen to be using custom formulas on an Excel Spredsheet, you have no options. Disabling the cancel key will not work because the thing breaks before it even runs the function and you have to restart your computer or else press continue for each and every function excel attempts to calculate.
There are a couple of ways to work around the problem.
Solution 1: Disable the ability to cancel
Drawback: If debugging, you cannot stop code by hitting ctrl+break. Lets hope you don’t get stuck in an eternal loop.
Solution 2: Save your work, close Excel, and restart your computer
Drawback: A REAL pain in the butt!
ANYONE FROM MICROSOFT WORKING TO FIX THIS.
- Proposed as answer by AllanonXXV Thursday, February 5, 2009 1:03 PM
- Unproposed as answer by danishani Tuesday, January 31, 2012 12:52 AM
True, The best Fix was indeed as listed in this Thread by A.D.T :
FIX:
TOOLS->Macros->Security->Medium security.
That at least enables the user to work again.
Not a permanent Fix, Yet It is practical for now.
Thanks to all who added input, It has really helped me out in a pickle.
I have the same problem with macros in Word. With Word 2007 there was much simpler solution than restarting computer: just lockig the computer and then unlocking. Now, with Word 2010 this trick doesn’t help — I must logoff and thne login to the computer.
But it’s only workaround, the problem is still in VBE.
After some googling I’ve found better (quicker) solution: just end macro, switch to the VBE and hit Ctrl+Break. After that the code execution doesn’t break.
Boris Lehečka (Word, Access, VBA, XML, C#, SQL)
- Marked as answer by danishani Tuesday, January 31, 2012 12:51 AM
This just started happening to me, and it is very localized.
I am basically starting fresh (fresh workbook) each time, and adding my VBA code using cut/paste from a code repository. I’m not importing anything, just pasting text. All of it runs just find, but very recently one particular OnClick routine stops at one particular statement. As with everyone else, if I resume execution it works just fine.
Here is a code snippet:
Private Sub CommandButton1_Click()
Dim SourceDirDialog As FileDialog
Dim SourceDir As String
Set SourceDirDialog = Application.FileDialog(msoFileDialogFolderPicker)
SourceDirDialog.Title = "Directory for web pages"
If Not SourceDirDialog.Show Then Exit Sub
‘ There can only be one item returned.
SourceDir = SourceDirDialog.SelectedItems(1) & "\" <— This is where it stops, every single time
Since this is happening in different workbooks, and persists through a reboot, and started very recently, I’m inclined to suspect IE9 did something.
- Marked as answer by danishani Tuesday, January 31, 2012 12:51 AM
This worked for me also.. Thanks..
After some googling I’ve found better (quicker) solution: just end macro, switch to the VBE and hit Ctrl+Break. After that the code execution doesn’t break.
- Proposed as answer by JohnQG Monday, April 30, 2012 2:44 PM
This also just worked for me : Ended macro, switched to the VBE and hit Ctrl+Break. After closing down the code window I got "This command will stop the debugger" message. Clicked OK, and this ended the debugging mode.
- Edited by kaganova Tuesday, September 13, 2011 5:02 PM
After some googling I’ve found better (quicker) solution: just end macro, switch to the VBE and hit Ctrl+Break. After that the code execution doesn’t break.
Boris Lehečka (Word, Access, VBA, XML, C#, SQL)
Have been finding this very annoying and very pleased to find this searching. It works!
- Edited by JFK555 Wednesday, October 12, 2011 1:52 PM
Thank You Boris.
Your solution helped me keep my sanity. It worked perfectly. Had to debug some code, finished the coding part and decided to run it and it kept breaking for no reason, click on debug and hit run again and it runs for a few more lines and breaks. I was almost ready to thrash my computer, but had to meet a deadline, so kept trying all sorts of suggestions people gave, nothing worked and this worked like a charm.
Found the Ctrl + Break solution here and it worked like a charm.
Thank You again.
Same problem here. For me it is not a problem to hit ctrl break or continue or go into debug mode., but I can’t let the end user do that though?
Isn’t there another solution for this terrible bug?
I’ve been a Developer since WordBasic/XL Dialog Boxes were upgraded to VBA way back when circa ’95, making it 20 years in a few days now.
This first showed up on a colleague’s machine running XP/Office 2003 way back then. I’d thought it might be specific to version 11 of the Office Suite and so I found the line to suppress the interrupt, though advised not to use it.
From here on out the only solution seems to be to never press Ctrl + Break and to write code with breakpoints, and step through live code, so it never goes into infinite loops. If that, or some other problem needs a Ctrl + Break, then press Ctrl+Shift+Esc to call up the Task Manager, and stop the task from there.
In the meantime, since this affects the same colleague again with a different setup, Win7 Enterprise/Office 2010, I have to find out what to do if this affects others with the beautiful applications that Microsoft’s Office Suite/VBA provides for.
The only thing I can think of is that the problem lies in a toggle between break or not and it gets stuck in break, just randomly breaking. The code that interprets my VBA is toggled the wrong way by hitting Ctrl + Break one time to get out of a circle, whether this is in the Forms or VB versions or perhaps a .dll I don’t know yet.
I’ve read this affects version 15 (Office 2013) too. I don’t know what to do at this point but to write to Microsoft for a patch.