Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Close UserForm by pressing Esc key

Hi,

I made a userform and I want to close this without pressing the Cancel
button or Close Button. is it possible to close it by pressing Esc
key.

Pls advise me.

Regards.

Shahzad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Close UserForm by pressing Esc key

I think the Userform will close with the Esc Key pressed by default. It does
for me in Excel 2007.

If not, I'd use,

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)

If KeyCode = 27 Then
Unload Me
End If

End Sub

"Shazi" wrote:

Hi,

I made a userform and I want to close this without pressing the Cancel
button or Close Button. is it possible to close it by pressing Esc
key.

Pls advise me.

Regards.

Shahzad

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Close UserForm by pressing Esc key

lol, I've been using Peter T method without even realizing it. Peters
response is the way to go, it works for me. The Esc Key will not close the
UserForm by default.

Look under the Properties Window of the command button you wish to use to
Unload the Userform. Set the Cancel Property = True. Sorry for any
confusion.

Ryan

"RyanH" wrote:

I think the Userform will close with the Esc Key pressed by default. It does
for me in Excel 2007.

If not, I'd use,

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)

If KeyCode = 27 Then
Unload Me
End If

End Sub

"Shazi" wrote:

Hi,

I made a userform and I want to close this without pressing the Cancel
button or Close Button. is it possible to close it by pressing Esc
key.

Pls advise me.

Regards.

Shahzad

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Close UserForm by pressing Esc key

Your form needs a button that has it's Cancel property = true. Put your code
to close the form in the cancel button's click event, eg

Private Sub CommandButton1_Click()
Unload Me
End Sub

Typically the button's caption would read "Cancel" or "Quit", so you could
click it or press Esc, but the button could be hidden off the form if you
want.

Regards,
Peter T

"Shazi" wrote in message
...
Hi,

I made a userform and I want to close this without pressing the Cancel
button or Close Button. is it possible to close it by pressing Esc
key.

Pls advise me.

Regards.

Shahzad



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform close Karen53 Excel Programming 4 March 11th 08 10:39 PM
Close Userform Bert[_2_] Excel Programming 1 October 21st 07 07:51 PM
Close Userform Bert[_2_] Excel Programming 1 October 21st 07 04:02 PM
Pressing a CommandButton on a Userform via Code Corey Excel Programming 5 January 19th 07 03:28 PM
close UserForm [email protected] Excel Programming 3 November 9th 06 02:33 AM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"