Is there someway in vba to cancel a popup when you hit the escape key?
Thanks
Mark
Is there someway in vba to cancel a popup when you hit the escape key?
Thanks
Mark
Re: cancel using escape key
Mark
Is it a popup generated by Excel or one you have created yourself?
When is it popping up?
Re: cancel using escape key
Hi
are you using a form under excel and you get a popup on pressing ESC (key) ???
Re: cancel using escape key
Im sorry I wasn't clear enough.
I have a script that pops up a calender when I double click any cell in colums D or E. I ant to give the user the ability to cancel the popup if he duble click by mistake. The red X is in the uper righthand corner to cancel, but my instant reaction to cancel a command is to press the esc key. That does not work. Which forces the user to move his mouse to the Red X, rather that just a simple keystroke. Therfore, my objective is to allow the unload of the popup calender by escape key.
I hope this clears things up.
Thanks
Mark
Re: cancel using escape key
Hi Mark,
Do you have a CommandButton on the userform that acts as a Close/Cancel button?
I usually have one that simply says:[vba]Private Sub CommandButton1_Click()
Unload Me
End Sub[/vba]Then in the Properties for the button set Cancel=True.
HTH
Re: cancel using escape key
I did have that, but the red X pretty much does the same thing. Also that still forces a mouse interaction, vs the desired keystroke.
Thanks
Mark
Re: cancel using escape key
Quote from BradfordI did have that, but the red X pretty much does the same thing. Also that still forces a mouse interaction, vs the desired keystroke.
Thanks
Mark
Mark, have a look @ what Richie says .... if you impliment this you will get the desired result ie Esc will unload the form.
Re: cancel using escape key
Mark
Ivan and Richie are right.
If you set the Cancel property of a button to True then the code behind it is run when the Escape key is pressed.
There is a similar property Default which works with the Enter key.
See the attached small example.
Re: cancel using escape key
Ivan, Richie & Norie,
I wanted to try to avoid adding another button, to a popup that already has 47 buttons, 2 list boxes, and a Red X button. But if thats they way I have to do it, then I guess one more button won't hurt too much.
Thanks very much to all of you,
Mark
Re: cancel using escape key
You can always hide the button - the user will never need to press it. However, when the user presses the escape key, Excel will act as though that button has been pressed, and carry out the unloading action.
Re: cancel using escape key
Quote from GreychildYou can always hide the button - the user will never need to press it. However, when the user presses the escape key, Excel will act as though that button has been pressed, and carry out the unloading action.
I was going to suggest that but tested it first.
It doesn't work.
Re: cancel using escape key
I just tried it as well ..... no go
Thanks for the suggestion though.
Mark
Re: cancel using escape key
Worked for me ???
I just made my UF wider, moved the button to this area and set the width back to original.
Re: cancel using escape key
Ivan
So you hid it without using the visible property?
Never thought of that.
Re: cancel using escape key
Sometimes its the simple things that are overlooked. Seriously, how easy was that. LOL.
Thanks, That works exactly the way I needed it to.
Don’t have an account yet? Register yourself now and be a part of our community!