PC Review


Reply
Thread Tools Rate Thread

Close UserForm by pressing Esc key

 
 
Shazi
Guest
Posts: n/a
 
      24th Jun 2008
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 With Quote
 
 
 
 
RyanH
Guest
Posts: n/a
 
      24th Jun 2008
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
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      24th Jun 2008
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" <(E-Mail Removed)> wrote in message
news:57676752-6231-4c74-a357-(E-Mail Removed)...
> 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 With Quote
 
RyanH
Guest
Posts: n/a
 
      24th Jun 2008
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
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close a Excel Workbook when close a userform in Outlook lars.oyangen@hamstad.no Microsoft Outlook VBA Programming 2 8th May 2008 02:54 PM
Close a form by pressing esc, how to do it without having a button John Sheppard Microsoft VB .NET 4 28th Mar 2008 08:00 AM
Pressing a CommandButton on a Userform via Code Corey Microsoft Excel Programming 6 19th Jan 2007 03:57 PM
Re: close a form by pressing ESC Tarakeshwar L Microsoft C# .NET 3 17th Sep 2004 09:27 AM
close a form by pressing ESC =?Utf-8?B?QWxleCBLLg==?= Microsoft C# .NET 0 16th Sep 2004 08:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 PM.