MACROS WONT RUN

J

JOSEPH WEBER

I have several macros I use on a daily basis and I tried to run them and
they give me an error of "Code execution has been interrupted" Can someone
tell me why I could be getting this message? I didn't hit contrl break and
have no idea what else i could have done wrong.
 
G

Gord Dibben

Post one of the offending macros

In the meantime step through the macro using Debug and F8 from the VBE
menu.

Maybe you can see where the error occurs.


Gord Dibben MS Excel MVP
 
D

dk

I have several macros I use on  a daily basis and I tried to run them and
they give me an error of "Code execution has been interrupted"  Can someone
tell me why I could be getting this message? I didn't hit contrl break and
have no idea what else i could have done wrong.  

This happens most of the times when you offen debug using CTRL +
BREAK, you put the following line in your macro:

Application.EnableCancelKey = xlDisabled

to avoid this.


-DK
 
J

JOSEPH WEBER

dk said:
This happens most of the times when you offen debug using CTRL +
BREAK, you put the following line in your macro:

Application.EnableCancelKey = xlDisabled

to avoid this.


-DK

This works, but I may have hit a button at the wrong time or something and
want to cancel the macro and can't. This just started yesterday and it is
affecting all of my macros. I have them saved in personal.xls. Is there an
option to run the macro step by step, because that is what it seems to be
doing. I can hit continue and the macro will run, but I set up the macros in
the first place so I don't have to sit here and manually do this.
 
C

Chip Pearson

Application.EnableCancelKey = xlDisabled

Be VERY careful with that. If you get into an unintentional loop,
you'll have to CTRL ALT DEL or TaskMgr to get out, and you'll lose
data and possibly corrupt the workbook.

A better approach is to set EnableCancelKey to xlErrorHandler. When
the user breaks, VBA throws an Error 18, which you can detect and take
the appropriate action. E.g.,

Application.EnableCancelKey = xlErrorHandler
On Error GoTo ErrHandler
'
' your code here
'
Exit Sub
ErrHandler:
If Err.Number = 18 Then
' break key hit. either
' get out,
' Resume to go back to the statement
' executing when Break was hit
' Resume Next to go back to the line
' after the line active when Break was hti
' prompt user for action then Resume
Else
' some other error
End If

End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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