Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Ctrl-Break in Excel

Status
Not open for further replies.

Hmadyson

Programmer
Mar 14, 2001
202
US
I would like to Disable Ctrl-Break. I have a lot of code running in excel, and users can always break it and stop what I am doing. I tried using
Applicaton.Onkey "^{BREAK}",""
but that did nothing. I realize that Ctrl-break is very helpful for coders, but it is very dangerous for hackers. There has to be away to get rid of it.
Thanks.
 
Disable
Application.EnableCancelKey = xlDisabled

Enable
Application.EnableCancelKey = xlErrorHandler
 
Kevin,

If you want to give users the ability to gracefully interrupt a lengthy operation, use the xlErrorHandler constant in conjunction with an error handler in your procedure. Example:

Code:
Sub HurryUpAndWait()

On Error Goto ErrTrap
Application.EnableCancelKey = xlErrorHandler
' Some time-consuming operation here

Exit Sub

ErrTrap:
If Err.Number = 18 Then
  If MsgBox ("Are sure you want to terminate the operation?",vbQuestion+vbYesNo,"") = vbNo Then Resume
End If
End Sub

Also, It's a good idea to thoroughly test your procedure before disabling the Ctrl-Break key, otherwise you won't be able break out of an infininte loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top