+ Reply to Thread
Results 1 to 3 of 3

Close particular userform (without closing another)

  1. #1
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Close particular userform (without closing another)

    Hi guys!

    I am actually coding VBA in PowerPoint but I think this issue is not specific to PowerPoint (correct me if I'm wrong):

    I have userform1 loaded (modal=false) that loads up (via command button) userform2 (modal=true).
    I need these modals set up like that so that the user can still interact with PowerpPoint (while having userform1 still showing/available) but don't want the user having any other ineractions until thery're done configuring stuff in userform2 (which will affect some stuff in userform1 as a result).
    The problem becomes apperant when i click on the close button (or unload userform2) - this causes userform1 to unload as well.

    I am aware of the Me.Hide command that can resolve the issue, but is it good practice? Is it ok to leave a userform running in the backround (even though it doesn't do much, and there's a good chance you might not need it after that one time that you did need it)?

    Can userform2 be unloaded without unloading userform1 at all, given their mentioned modal settings, or is the Me.Hide the standard solution for this kind of senario (not just a workaround)?

    Thanks!
    Last edited by guyglk; 03-23-2019 at 02:44 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,758

    Re: Close particular userform (without closing another)

    You are right; this is a VBA question that is not specific to an application, so I will let it stay in this subforum since it will probably get more views that way.

    If you Hide instead of Unload, the form is not "running in the background." The form is not doing anything at all. But its state is preserved for the next call to Show, so it looks like it did when it was hidden, all static variables still retain their values, and it is still extant (its public variables and its controls can be accessed by other modules and any changes "stick").

    It is not a bad practice.

    In general, it is better to Unload if you want to force everything to be reset the next time you open the form. If you Hide, then you may need code to re-initialize the content of controls and the values of static variables.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Re: Close particular userform (without closing another)

    Thanks!

    The Hide command is actually perfect for the way I'm using userform2 (which acts as a change settings window for something shown in userform1 that I want the user to be able to configure (having an OK and Cancel button for saving or not saving the configurations in the end) so it cuts down a bit of code - than if I were to unload the userform, I guess.

    I wasn't really sure what happens once a userform is on screen (if it eats up any resorces or whatever...). [I'm not a coder (ameture here), so don't know the ramifications of code under the hood, so to speak...]

    Thank you for shedding some light on this!

+ 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. ActiveWorkbook.close is closing all workbooks
    By johnvn in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-27-2017, 05:06 AM
  2. how to close userform using commndbutton and set automatic close at certain time
    By fatinmunie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2014, 12:51 PM
  3. [SOLVED] ActiveWorkbook.Close closing sheets, but not the window
    By mintymike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2014, 07:36 AM
  4. [SOLVED] Close Active Sheet Without Closing
    By ISUSA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-21-2013, 09:35 AM
  5. before close not working on closing workbook
    By JoProvis in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-29-2009, 11:18 AM
  6. [SOLVED] close workbooks without closing excel ?
    By Clute in forum Excel General
    Replies: 2
    Last Post: 08-05-2006, 04:50 PM
  7. How do I close excell worksheet without closing others still open
    By John in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-20-2006, 01:20 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