Results 1 to 6 of 6

Thread: 'code execution has been interrupted' - phantom breakpoints?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2012
    Posts
    90

    'code execution has been interrupted' - phantom breakpoints?

    I've got an Excel macro I've been working on for some time. I keep having this problem when testing it where VBA pauses the macro and shows a dialog that says "Code Execution Has Been Interrupted" and shows a line of code highlighted. There is no breakpoint set for this line of code and I have no idea why my macro would pause there. If I hit F5 then execution continues to only to halt at another line of code (with no break point). I've tried toggling these breakpoints on and off but this does not solve the problem. I've tried closing and re-opening excel and that doesn't help either. How do I fix this? I'm worried that my Excel file might be corrupted.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: 'code execution has been interrupted' - phantom breakpoints?

    does your code write to vba modules?
    either way show the code that has problem, indicating which lines break the code
    or better post a sample workbook that demonstrates the problem
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: 'code execution has been interrupted' - phantom breakpoints?

    A quick search on this issue seems to indicate that it is not related to your code or Excel file in anyway, but rather that something in Excel gets mucked up. I am posting the relevant links and text from the links (as links have a nasty habit of becoming unavailable in a few years).

    The following is the best synopsis of the issue that I ran across.

    http://ask.metafilter.com/112071/Cod...en-interrupted
    In Excel VBA, you can hit ctrl+break to interrupt your code execution. When you do so, you get a window with the options:
    Continue, End, Debug, and Help.

    This is useful when you WANT to jump into your code to debug, but I've noticed something odd. If I ctrl-break, then immediately click 'continue' or 'end', 9 times out of 10 (though usually 100% of the time) the code will enter a mode where it will randomly throw the "Code Execution has been interrupted" window as if I hit ctrl-break, even though I didn't.

    Clicking Debug to see where it's stopped shows it halting at different lines everytime. Ending then restarting the code doesn't reset anything. Even restarting Excel won't fix it. It's like once that 'mode' gets activated, I'm stuck with it until I restart windows. (which so far is my only sure-fire solution)

    I've found 2 workarounds:
    1. if the 'mode' hasn't begun and I ctrl-break but then hit the F8 button several times(which advances the code execution by several lines), BEFORE clicking 'end' or 'continue', it doesn't seem to activate the 'weird' mode. (Conversely, if I ctrl-break and then immediately click on END or Continue, without advancing, it will start misbehaving)

    2. If I put in the line:
    Application.EnableCancelKey = xlDisabled
    then this will shut off the Debug window Entirely, allowing the code to finish running without interruption, but it also has the side-effect of preventing ME the ability to ctrl-break, which isn't useful when I'm trying to debug.

    I've done a lot of searching on this error over the past couple years (culminating in workaround 2 above), but there doesn't seem to be any useful help for this exact error. I'd love to know what is going on so I can stop it. Having to restart umpteen times a day or disabling code interruption is not making my life very efficient.

    Most 'helpers' refuse to even help unless the user posts code, which in this particular error isn't helpful since there is no pattern. In addition, my coworkers aren't able to recreate the error on their computers unless I'm logged in. (indicating to me, it's a profile issue or even a template problem; see 1. below)

    There are a few general tips I've found and tried to no avail.
    1. VBA bloated templates But I'm not using any templates, unless it's the default one, but I always close "Book1" when I start Excel.

    2. third-party add-in(s). I had a couple that were continually trying to load up, but I've disabled them and it doesn't seem to help

    3. Export all code and re-import it. This didn't help at all.

    The following solution appears to have the best results other than the "Application.EnableCancelKey = xlDisabled" hack that really is not a solution.

    http://stackoverflow.com/a/5823507/2592875

    I have found 2nd solution.

    I just press "Debug" button in the popup, then press twice [Ctrl+Break] and after this can continue without stops.

    Hope this helps someone.
    I also found several people who suggested doing a Repair-Install versus a straight re-install of Excel.

    I wish you good luck in resolving this issue.
    Last edited by TnTinMN; Oct 6th, 2014 at 05:08 PM. Reason: typos

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2012
    Posts
    90

    Re: 'code execution has been interrupted' - phantom breakpoints?

    Quote Originally Posted by westconn1 View Post
    does your code write to vba modules?
    It does not.

    Quote Originally Posted by westconn1 View Post
    either way show the code that has problem, indicating which lines break the code
    I neglected to indicate this in my post, but the lines of code worked fine for weeks and appear to have no inherent condition or runtime possibilities which would force a debug halt like the one I described. Also, the second 'phantom breakpoint' as I call it is not consistent. It usually halts on a line in the middle of a with block. Furthermore, hitting F5 (as I mentioned in the OP) will cause the code to continue execution without any errors. The essence of the problem is not that I'm getting errors, but that something is halting my code for no reason.

    Quote Originally Posted by westconn1 View Post
    or better post a sample workbook that demonstrates the problem
    Unfortunately, the workbook contains proprietary material which I am not at liberty to share.

    Having read TnTinMN's post and having spoken to a more experienced VB dev, I'm pretty sure this is one of those really annoying systemic problems with Excel. I really appreciate the detail and links, but am sad that there does not seem to be a reliable fix for the issue. I'm concerned about this problem popping up on my client's machine even if I fix it on my machine. I'm also reminded of a similar problem from about 20 years ago.

  5. #5
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: 'code execution has been interrupted' - phantom breakpoints?

    Quote Originally Posted by sneakyimp View Post
    .... but am sad that there does not seem to be a reliable fix for the issue. I'm concerned about this problem popping up on my client's machine even if I fix it on my machine. I'm also reminded of a similar problem from about 20 years ago.
    You may want to try and post a bug report on Microsoft Connect. However, do not expect to get either a quick or satisfying response from them. I tried to search there for this issue earlier before posting and I did not have any luck finding a reported issue. The reason my pessimism on reporting the bug, is that 1) it is intermittent, 2) you can not provide a sample to reproduce the error, and 3) my complete disgust with their response to my own reported bugs and those of others (ticket closed - won't fix or my personal favorite "By Design"). That said, it may help if you can point them to a bunch of links where others have been discussing the same issue. Even if they are willing to fix the bug, most likely it won't be fixed until the version is released.

    Good luck.

  6. #6
    Registered User
    Join Date
    Oct 2014
    Posts
    6

    Re: 'code execution has been interrupted' - phantom breakpoints?

    Hello sneakyimp,

    I have faced similar situation while debugging code by pressing CTRL+Break 2 to 3 times when again if I try to run(F5) then its start pausing with out interruption. SO I just presses Ctrl+Break again when code stopped automatically and then it doesn't happens again.

    Weird but worked

    Try it out This may work in your case as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width