jana
asked on
How to know via code when a user presses the windows X' or the ESC key in a VBA apps
We are trying to determine how to capture in the VBA code (specifically in Outlook VBA) when a user clicks the "X" button of the UserForm window and also if the user presses the ESCAPE key on the keyboard.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
We have a UserForm that does a drop-down combobox window.
We have a Boolean variable named 'OptionNotSelected' that we want to set to TRUE when the user either press the ESCape keyboard or clicks on the "X" of the UserForm to exit.
We have a Boolean variable named 'OptionNotSelected' that we want to set to TRUE when the user either press the ESCape keyboard or clicks on the "X" of the UserForm to exit.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
doesn't work
Please show the exact code you are trying, and explain what you mean by "doesn't work".
ASKER
I just copied your exact code. Attached is an example in a an Excel (we have to do this for both an Excel and Outlook).
TestEsc-Xbutton.xlsm
TestEsc-Xbutton.xlsm
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, you initial script was placing it in the UserForm, we have to place it in the field area not the form.
How about when clicking on the "X" corner ?
How doe we use your script:
If CloseMode <> 1 Then
Cancel = True
MsgBox "The Close box has been disabled", vbExclamation, "No soup for you!"
End If
How about when clicking on the "X" corner ?
How doe we use your script:
If CloseMode <> 1 Then
Cancel = True
MsgBox "The Close box has been disabled", vbExclamation, "No soup for you!"
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I placed it in the UsertForm1 and it didnt work.. Do i have to put it in the fields (TextBox)?
ASKER
It did worked!
Thanx!!
Thanx!!
escape won't work in the form itself but the close will as it is not in the text box where the 'textbox' has the focus all the escape key does is clear the box
ASKER
Dont understand, I tried it and it works, ESC key when pressed is being captured.
ASKER
Thanx
ASKER