Hi,
A few questions on the matter...
Is there is "conservative & responsible" way to disable Crt+Break ? I understand the dangerous infinte loop & to debug first.
But a user is bound to do something a developer did not anticipate.
How can one responsibly disable ^break with:
a. one code for all macros
b. a msgbox something sufficiently discouraging so that he/she does not repeat action, like "Illegal keystroke. This program will now terminate!', vbcritical,"program Shutdown" or perhaps something more forceful
c. save & Exit workbook only not quit all open workbooks?
Thanks again
Mohamed
A Responsible way to Disable Ctrl+Break
-
- 3StarLounger
- Posts: 366
- Joined: 12 May 2010, 06:49
-
- StarLounger
- Posts: 78
- Joined: 10 Feb 2010, 12:54
- Location: Jeddah, Saudi Arabia
Re: A Responsible way to Disable Ctrl+Break
Google disable control break in visual basic for applications
There are lots of good examples there.
Regards,
Kevin Bell
There are lots of good examples there.
Regards,
Kevin Bell
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: A Responsible way to Disable Ctrl+Break
The Application object in Word and Excel has a property EnableCancelKey that determines how Ctrl+Break is handled. See EnableCancelKey Property  [Word 2007 Developer Reference] and EnableCancelKey Property [Excel 2007 Developer Reference].
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 366
- Joined: 12 May 2010, 06:49
Re: A Responsible way to Disable Ctrl+Break
Hi,
Thanks for pointing me in the right direction.
Kind Regards
Mohamed
Thanks for pointing me in the right direction.
Kind Regards
Mohamed
-
- 3StarLounger
- Posts: 366
- Joined: 12 May 2010, 06:49
Re: A Responsible way to Disable Ctrl+Break
Hi,
Following on the previous post, do I have to:
a. place code this in every procedure?
b. where a macro calls another macro then in each "submacro" also?
Sub MyProcedure()
'Dim statements
On Error GoTo HandelCancel
Application.EnableCancelKey = xlErrorHandler
‘code
HandelCancel:
If Err.Number=18 Then
If MsgBox ("Are sure you want to terminate the operation?",vbQuestion+vbYesNo,"") = vbNo Then Resume
End If
End Sub
Following on the previous post, do I have to:
a. place code this in every procedure?
b. where a macro calls another macro then in each "submacro" also?
Sub MyProcedure()
'Dim statements
On Error GoTo HandelCancel
Application.EnableCancelKey = xlErrorHandler
‘code
HandelCancel:
If Err.Number=18 Then
If MsgBox ("Are sure you want to terminate the operation?",vbQuestion+vbYesNo,"") = vbNo Then Resume
End If
End Sub
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: A Responsible way to Disable Ctrl+Break
a. Yes - if you really want to do this.
b. No - when a macro calls another macro, the setting of Application.EnableCancelKey is preserved, so you don't have to set it in the "submacro". Only when ALL code has finished running does Excel reset Application.EnableCancelKey to the default xlInterrupt.
b. No - when a macro calls another macro, the setting of Application.EnableCancelKey is preserved, so you don't have to set it in the "submacro". Only when ALL code has finished running does Excel reset Application.EnableCancelKey to the default xlInterrupt.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 366
- Joined: 12 May 2010, 06:49
Re: A Responsible way to Disable Ctrl+Break
Thank you Hans for the quick & precise reply.
Kind Regards
Mohamed
Kind Regards
Mohamed