Put a commandbutton on your userform and write the below code on command button Click event.
Private Sub CommandButton1_Click()
Then set cancel to true in its property. See image below(Click on the image to enlarge it)
Now when you run userform and press escape key on your keyboard userfrom will be closed.