Results 1 to 6 of 6
  1. #1
    sgerber
    Guest

    Esc key to dismiss dialog?

    This is probably a really dumb question, but what the heck...I'm new at VBA.

    Dialog boxes created in WordBasic could be dismissed, like most any other Windows dialog box, by pressing the Esc key. For the couple I've created in VBA, that doesn't seem to be the case.

    Is there a way to make VBA dialog boxes respond to the Esc key?

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Esc key to dismiss dialog?

    If you are talking about a VBA UserForm, then you just need to put a "Cancel" button on the form and in the properties for that button set the Cancel property to True. Then pressing Esc while the form has focus will execute the click code for the button.
    Legare Coleman

  3. #3
    sgerber
    Guest

    Re: Esc key to dismiss dialog?

    Thank you, Legare!

    That was driving me nuts.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Esc key to dismiss dialog?

    I knew about the Cancel button, but for some strange reason your response prompted me to try this:


    <pre>Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    If KeyAscii = 27 Then Me.hide
    End Sub
    </pre>



    It works, and if it weren't Sunday I'd locate the wd identifier for the Escape key.

    I do wish you wouldn't send my brain off like that.

    And Steve Gerber, if you're still there, let me be the first to echo THERE ARE NO DUMB QUESTIONS!

    As evidence of THAT, see what your enquiry prompted me to discover?

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Esc key to dismiss dialog?

    You should be able to use the VB constant vbKeyEscape, even in Word. <img src=/S/grin.gif border=0 width=15 height=15>
    Charlotte

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Esc key to dismiss dialog?

    I agree. You just saved me looking up the HELP files (grin!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •