Consulting

Results 1 to 3 of 3

Thread: Unload userforms

  1. #1

    Unload userforms

    I have a main menu userform with several sub menu userforms which are accessed from the main menu. On the sub menus are buttons that when clicked on open a specific spreadsheet. Once the spreadsheet, how do I get excel to close all the sub menu userforms and the main menu userform?

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Hi, Welcome to VBAX

    The following should do:

    [VBA]Private Sub CommandButton1_Click()
    ' Open Spreadsheet here
    ' If spreadsheet opens, close all forms
    Unload Me ' Userform3
    Unload UserForm2
    Unload UserForm1
    End Sub[/VBA]

    The idea is to unload the topmost userform first, and then go down the list backwards to how you opened the userforms.

    Check out the attached file.

    If you are using Modeless forms, the code will still work.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    If you unload the main menu when you open a sub menu, then all you have to do is put Unload Me at the end of your button code. You can also use variables to instantiate the forms, put all the variables into a collection and just destroy that at the end.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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