ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error handling and escape key (https://www.excelbanter.com/excel-programming/387632-error-handling-escape-key.html)

Jeff[_54_]

Error handling and escape key
 
I'm trying to catch the {Escape} key and not allow it to put up an
error when my form is open. I have one of my command buttons set to
cancel true already, but it doesn't always catch the key press. I've
found some mention of using this

On Error GoTo ErrorHandler
Application.EnableCancelKey = xlErrorHandler

But I'm not really sure where to put these lines. I put them in my
UserForm_Initialize sub and I get 'Label not defined' for ErrorHandler
on compile. I'm not exactly sure where I should put this where it
will always be active. Any help would be appreciated.


Roger Whitehead

Error handling and escape key
 
Have you tried Application.OnKey?

Application.OnKey "{ESC}", ""
will disable the Escape key,
Application.OnKey "{ESC}"
will re-enable


HTH
Roger
Shaftesbury (UK)




"Jeff" wrote in message
oups.com...
I'm trying to catch the {Escape} key and not allow it to put up an
error when my form is open. I have one of my command buttons set to
cancel true already, but it doesn't always catch the key press. I've
found some mention of using this

On Error GoTo ErrorHandler
Application.EnableCancelKey = xlErrorHandler

But I'm not really sure where to put these lines. I put them in my
UserForm_Initialize sub and I get 'Label not defined' for ErrorHandler
on compile. I'm not exactly sure where I should put this where it
will always be active. Any help would be appreciated.




Roger Whitehead

Error handling and escape key
 
Jeff,
You'll need the

ErrorHandler:

Label in the same module that calls it.




Have you tried Application.OnKey?

Application.OnKey "{ESC}", ""
will disable the Escape key,
Application.OnKey "{ESC}"
will re-enable

Not sure just how effective this would be in a user form though.

HTH
Roger
Shaftesbury (UK)



"Jeff" wrote in message
oups.com...
I'm trying to catch the {Escape} key and not allow it to put up an
error when my form is open. I have one of my command buttons set to
cancel true already, but it doesn't always catch the key press. I've
found some mention of using this

On Error GoTo ErrorHandler
Application.EnableCancelKey = xlErrorHandler

But I'm not really sure where to put these lines. I put them in my
UserForm_Initialize sub and I get 'Label not defined' for ErrorHandler
on compile. I'm not exactly sure where I should put this where it
will always be active. Any help would be appreciated.





All times are GMT +1. The time now is 11:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com