+ Reply to Thread
Results 1 to 10 of 10

How do you close a window with a hidden UserForm in it?

  1. #1
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    How do you close a window with a hidden UserForm in it?

    Hi,

    Is there a work-around for safely closing an Excel window when there is a hidden UserForm in it?

    I have a multipage UserForm with a "close" command button that hides the form. And if while that form is hidden the user clicks the Excel "Close Window" button (the small X on the toolbar under the big X that closes the entire program), Excel crashes. I guess Excel does not like to shut down an active window with a hidden UserForm in it.

    Is there a way around this...other than simply not using the "hide" in VBA?

    Lawrence
    Last edited by skysurfer; 04-16-2010 at 07:59 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do you close a window with a hidden UserForm in it?

    Hello Lawrence,

    Instead of hiding the UserForm, I have code to make the UserForm behave like a Window with minimize, maximize, and a close buttons. This will allow you to either close it completely when you are done using it or minimize it to get it out of the way. Let me know if you are interested.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you close a window with a hidden UserForm in it?

    Leith,

    That code sounds very cool. What happens if the user closes the Excel window (the little X) when one of your forms are minimized or maximized?

    Lawrence

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do you close a window with a hidden UserForm in it?

    Hello Lawrence,

    The UserForm will remain until the user closes it.

  5. #5
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you close a window with a hidden UserForm in it?

    Leith,

    Could I try out your code. It sounds like it really takes the UserForm to the next level!

    Lawrence

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do you close a window with a hidden UserForm in it?

    Hello Lawrence,

    It is important that you set the UserForm ShowModal property to False for this to work correctly. Copy the macro code below into its own VBA module.
    Macro to Add Window Buttons to a UserForm
    Please Login or Register  to view this content.


    UserForm Code
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you close a window with a hidden UserForm in it?

    Leith,

    This looks awesome. If I use it I will definitely preserve the header.

    Dumb questions:

    1. Is Modeless the same as setting the modal property to false? The Userform is currently coded to launch modeless as it is meant to be moved around and out of the way of charts.

    2. Will I still be able to initialize the UserForm? I have a lot of code in the initialization procedure.

    Thanks!

    Lawrence

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do you close a window with a hidden UserForm in it?

    Hello Lawrence,

    Yes and yes.

  9. #9
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you close a window with a hidden UserForm in it?

    Quote Originally Posted by Leith Ross View Post
    Hello Lawrence,

    Yes and yes.
    Stay with me...got momentarily dragged into another direction on this project. Excited to try your code. I'll keep you posted!

    Lawrence

  10. #10
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you close a window with a hidden UserForm in it?

    Leith,

    This is very cool stuff.

    Thank you!

    Lawrence
    Last edited by skysurfer; 04-16-2010 at 09:24 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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