+ Reply to Thread
Results 1 to 4 of 4

Userform Controls shortcut - close userform by escape key

  1. #1
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Userform Controls shortcut - close userform by escape key

    i created a userform (call it userform1) that launches another userform (call this userform2). excel is hidden from user's view (by application.visible = false) upon launching userform1 (modal) so only the userforms are visible.
    i wanted userform2 to hide or unload when i press the "{ESC}" button (escape key).

    i tried:
    1.) putting a command button (call it "Hidekey") setting it to default key and code it to close the userform2 (works but not ideal closing userform2 with the enter key on keyboard)

    2.) assign an accelerator key ("H") on hidekey
    (not ideal closing userform2 with two buttons to press - Alt+H)

    3.) run code: (on initializing userform1)
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    -(the code above is not the accurate code) i made this one work, BUT, it only works when excel is Visible from user's view - pointless


    so..
    has anyone tried assigning like escape key to close a userform while excel is not visible (only the userform is visible) if yes, please help...
    Or.. Does anyone have a better idea...
    don't worry, there's a lot of people that are far more confused than you
    but if you liked what i suggested. Click for me the "Add Reputation" - that way, we'd be both happy.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Userform Controls shortcut - close userform by escape key

    Try the KeyPress event procedure.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: Userform Controls shortcut - close userform by escape key

    for some unknown reason, that didn't work...

    i tried it while excel is visible and with the userform1 and userform2
    tried it while excel is not visible and only userform1 and userform2 are visible
    and i tried it again while only excel is showing - no userform loaded... (just to see if it would error or what at least)

    (i added the code within userform2's module)
    am i missing something extra i need to add?
    Last edited by ag273n; 05-05-2014 at 07:21 AM. Reason: added info

  4. #4
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: Userform Controls shortcut - close userform by escape key

    so i just found out something....
    check this out:


    http://excelvbatipsforbeginners.blog...scape-key.html


    goodness gracious, i set up hidekey with property "Cancel" to true, and it WORKS!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Escape key on UserForm also cancels the next UserForm to appear?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-09-2014, 02:26 AM
  2. Close Userform from within child Userform
    By contaminated in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2014, 04:24 PM
  3. How to Open 2nd workbook from userform, then close 2nd Userform
    By bigfoot007 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2012, 02:03 PM
  4. userform controls
    By natanz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2005, 06:20 PM
  5. [SOLVED] UserForm Question:Is it possible to save and close a file via a userform.
    By jer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-13-2005, 08:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1