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?

cheers

simon

Advertisements

19 Responses to “Code execution has been interrupted”

  1. Michael K Says:

    I have the same problem every once in awhile. I can never figure out how to fix it. Sometimes a restart fixes it and sometimes not, but it always goes away eventually.

    Praying someone has a real answer.

  2. Bob Phillips Says:

    I regularly get it. I did find out why once and what to do ab out it, but I have forgotten, and Continue seems to work fine, so I have learned to live with it.

  3. Harlan Grove Says:

    A bug in the VBA engine itself? Or could this be a protective measure against stack overflow? How deeply nested are the calls which trigger this?

  4. sysmod Says:

    Repair Excel installation?
    http://stackoverflow.com/questions/2154699/excel-vba-app-stops-spontaneously-with-message-code-execution-has-been-halted

    you’ve obviously googled for all the other posted ‘solutions’, which probably rely on the random nature of the occurrence to make it look like they worked for a while.

    “end macro, switch to the VBE and hit Ctrl+Break. After that the code execution doesn’t break.”
    “I stopped it by editing something in hte code, pressing Ctrl+Shift+F9 to clear all breakpoints and then recompiling and saving.”

  5. Hiran Says:

    What I found is … I always get this after I have hit Ctr-Break to break out of being stuck in a loop. In my experience, the only way is to reboot the machine. Restarting Excel is not enough.

    not sure why.

  6. Dick Kusleika Says:

    Like Hiran, I get it when I break into the code. It’s like Excel puts a break point in the code that never quite gets removed. Exporting the modules and reimporting has fixed it for me 100% of the time.

  7. Simon Says:

    Hirans/Dicks experience sounds nearest (although Bobs is familiar too (‘I used to know that…’)) :-)
    Crtl break is for me just before killing the process, If pressing the escape key increasingly harder does not fix it (or wiggling the mouse very very fast) then crtl break then kill. This happens a lot here, mainly because we are working with ADO which is a regular Excel killa.
    Michael – I read that as ‘praying is sometimes the answer’, I was going to say, not sure about that but swearing loudly seems to help,
    In this case I think one of my team mates was a ctrl break fan, and I was working on a test machine.
    this seems like it has scope for a ‘funny’ trick for fellow Excel/VBAers – get them to crtl break their code – watch as they suffer till the next reboot…I’ll try it as an ice breaker on my next contract…;-)
    Harlan, it was 6 or 8 levels down, and it did seem a bit like a security thing, with it breaking on access to the Excel OM, but also it was like a ghost break point, which cleaning usually fixes,
    Patrick, thanks for the link, that sounds exactly like it, I think I tried clearing BPs and recompiling.

  8. Marcus from London Says:

    Yup, I’ve had this several times in the past as well.

    What I noticed is that the ‘interruption’ occurred on lines where I had previously had break points.
    Resetting and then removing the break points didn’t work.

    What did work for me (YMMV) is restarting Excel (flush the memory) then exporting and re-importing all the objects (modules, class & forms) which seemed to clear up this ‘phantom’ break point.

    Cheers – Marcus

  9. Hiran Says:

    I have learned from this thread: No need to reboot the PC (as I do), just exporting/re-importing the Module will be sufficient (not tested by me yet, but I confirm that rebooting the PC works), and restart Excel as Marcus says.

    Marcus, in my experience, the ‘code interruption’ occurs at various random points, not at any previous breakpoints. But I suspect, when I hit Ctrl-Break I do not know at point in the code execution I hit it – so I suppose there is some truth in what you discovered. (so, learned that too).

  10. ross Says:

    sounds like time for Robs code cleaner!

    Never had this issue myself to be honest. But I never need to debug ;-)

    • Bob Phillips Says:

      Ross,

      You know that debugging is twice as hard as writing the code in the first place. Therefore if you write your code as cleverly as possible, you are, by definition, not smart enough to debug it!

  11. Simon Says:

    Ross I was going to say something similar about breaking out of never ending loops. I dont do never ending loops. ever.
    unless its recordsets then 100% of times I forget .movenext and get an infinite loop.
    Bob that is a good point, and perhaps explains some of the total pap I have worked with recently – people giving themselves some leeway to be able to debug, by writing it as dumb as possible first.

  12. Charlie Hall Says:

    Maybe along the same lines, I am now getting this error message from VBA “This action will reset your project, proceed anyway” but it does this when I open the workbook – and it still then runs the thisworkbook.workbook_open macros – so nothing seems to be lost just annoying. Has anyone seen this?

    The one downside is that when I try to open this workbook using code, the whole thing hangs, because, I am assuming, that it is waiting for a response to this dialog, but the dialog does not show up when I use workbooks.open

    I have tried cleaning the project, but to no avail

    Any suggestions?

  13. NeverFlute Says:

    Sysmod method worked for me.

  14. TheVBCoder Says:

    Esc or Ctrl-Break is a normal feature of Excel. It allows the programmer to break execution of the code in the event during development it gets stuck in a loop. Normal users certainly should not be hitting Ctrl-Break. Of course they are expected to hit Esc so in that case this issue can pose a problem. The problem is easily repeatable by simply hiting Esc when you know your code is still executing code. Test it by forcing a 1 or 2 sec code to run and hit Esc several times. 2 times out of 10 you will get this message. So the solution to me is 1) Make your code run faster. or 2) use the Application.EnableCancelKey = xlDisabled before the slow code and the xlInterrupt when you are done.

  15. Simon Says:

    ? perhaps the post wasn’t clear ?
    The interruption was not triggered by anyone

  16. Weird Macro Break Says:

    […] […]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: