excel vba close form escape key

The solution for “excel vba close form escape key” can be found here. The following code will assist you in solving the problem.

‘ 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

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

Similar Posts