Can't enter break mode at this time

泄露秘密 提交于 2019-12-01 10:49:19

Here are a few suggestions which are not fool-proof,

Firstly, verify that the error does not occur if a breakpoint is not set.

If it doesn't, try a few other things:

  1. From the VBE Debug menu, "Compile VBA Project", it's worth a shot.
  2. Delete the line entirely. Run the code. Then put the line back in and try again with the breakpoint.
  3. Add a DoEvents statement after the Sheets.Add
  4. Use a MsgBox instead of a breakpoint on a Debug.Print. With the message box displayed, attempt to manually break using ctrl+fn+End. (At this point, "breaking" isn't necessary but it would be interesting to see whether you can break this way)
  5. Put a breakpoint on Sheets.Add instead; practically speaking, there's no reason to put the breakpoint on a Print statement if you can just put it on the preceding line.
  6. Are there any Addins? If so, disable all of them and re-enable one at a time, testing to see which one may contribute to the error.

Yet another Excel/VBA glitch.

When it happens to me when I click a button running a macro:

  • I first try to directly run the macro from VBE,
  • if it fails, then I put a breakpoint at the first instruction of the macro,
  • if it still fails, I try both,
  • or, after clicking the button and breaking on the first breakpoint, I do a single step (SHIFT F8) and then I can let debug run freely as usual (F5).

And so far I don't get this error anymore.

Probably not foolproof either but worth a try.

Check if Microsoft for Visual Basic for Applications Extensibility is being referenced/used in the project. This prevents the program having its execution suspended:

Excel helps says specifically:

A change was made programmatically to the project using the extensibility (add-in) object model. This prevents the program from having execution suspended. You can continue running, or end execution, but can't suspend execution.

You are unable to step through code when making changes to the project (dynamically eg using InsertLine etc). the code can be run but not stepped through.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!