Question : excel vba close form escape key
Answered by : vastemonde
' In the userform code (must also be command controls if any,
' for example buttons, for Keypress event)
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii = 27 Then Unload Me
End Sub
' Or on at least one / all buttons:
button.Cancel = True
' Or if none add a button to the userform with:
With button .Height = 0 .Width = 0 .Cancel = True
End Width
Source : | Last Update : Sun, 14 Feb 21