Possible Duplicate:
Excel VBA App stops spontaneously with message “Code execution has been halted”
Why does VBA execution stop 开发者_如何学Cat random points within the code with the message "Code execution has been interrupted" unless the following has been specified:
Application.EnableCancelKey = xlDisabled
The stop in the code is similar to a Ctrl+Break key stroke and hence, disabling the Cancel Key (Ctrl+Break) avoids the stop in the execution.
However, disabling the Cancel Key is a bad idea for me because certain scenarios in my code can cause infinite loops (If an OLE request never completes for example) where the ability to use Ctrl+Break is priceless.
I am not too keen on setting EnableCancelKey
to xlErrorHandler
either. It would be better if I could understand the reason for the code interruption and avoid it rather than changing the behavior of the Cancel Key.
It's most likely a corruption of the p-code that's created when you compile. Some people have had success by choose Clear All Breakpoints from the Debug menu. The rock solid method is to export all of your modules, delete them, then reimport them. This round trip through plain text forces a complete rebuild of the p-code. Google for Rob Bovey's Code Cleaner for a free utility that automates this process.
精彩评论