Disable the PauseBreak key

L

leerem

gentelmen,
I'm working on a spreadsheet that is primarily run by code, by
use of userforms.
What i need is to stop some inquisitive personell from attempting to break
out of the code by the use of Control + PauseBreak keys.

How can I therefore Disable this combination of key strokes. Should this
occur all the information held within memory on the specific userform will be
lost.

your help would be appreciated
lee
 
A

AB

check out
application.EnableCancelKey

You can set it to enable/disable/Error
and then code accordingly. The 'error' let's you trap it by raising an
error - i think the err.number=18.
 
L

leerem

Hi,
thanks for the info I've tried placing some code in the Userform Terminate
section but it wont launch upon the keystroke combination.

Would i be asking too much if you could supply some code and at what section
would this be applied

many thanks
 
A

AB

This code worked for me on a userform1 with CommandButton1 :

'Userform module:

Private Sub CommandButton1_Click()

Me.Hide

Dim rng As Range

On Error GoTo CanclErr:
Application.EnableCancelKey = xlErrorHandler

For Each rng In ActiveSheet.Cells
If rng.Row = 2000 Then GoTo ExtFinished: 'Just to kill it it
when it takes too long - for ilustration puroposses only
rng.Value = 1' Obviously your code would do whatever it needs
to do
Next

ExtFinished:
Exit Sub

CanclErr:
MsgBox "Nope, you should not be cancelling this!"
Stop 'This is here just so that you could see when it traps the
error. You don't need it in your final code.
Resume

End Sub

''''''''''''''
'Standard module:

Sub tryCancel()
UserForm1.Show
End Sub


Give it a try.
 
A

AB

Forgot to mention that you don't need this:
Me.Hide

in the code in case your form isn't Modal.
I don't know if you can change that on the fly - would need to do some
research on that one. This would matter to you if you want to trap the
Esc instead of just disabling it.
 

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