Code execution has been interrupted

A

AnExpertNovice

Is there a way to prevent the "Code execution has been interrupted" error?
I'm thinking there is not, but perhaps my code is incomplete or inadequate.

A worksheet has the following event handler: (A similar handler exists for
the workbook.)

Private Sub Worksheet_Deactivate()
'Redisplay Formula Bar when changing to another worksheet
On Error Resume Next
Application.DisplayFormulaBar = True
End Sub

When I start to Alt-Tab to change to another window and use the Esc key to
change my mind then the Esc key must be pressed a second time to avoid the
interruption error when any code is executed. Of course, code will be
executed if I change worksheets, workbooks, click a button, etc.

Any suggestions?
 
B

Bob Umlas

Put this as the first statement in your code:
Application.EnableCancelKey = xlDisabled
this effectively turns off the esc key, but if you have a real problem, like
a loop, you would have to ctrl/alt/delete to stop it.
 
A

AnExpertNovice

Interesting command. It is the Alt-tab + Esc that causes the problem. A
second Esc prevents it. Plus, the problem is caused when no code is
executing and the problem manifests itself when code begins to execute.

Application.EnableCancelKey will be set to xlInterrupt state when the
problem is caused and when it rears it's ugly message box.

Thanks for the command. I can see uses for this one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top