+ Reply to Thread
Results 1 to 12 of 12

Best way to hide workbook behind userform

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Best way to hide workbook behind userform

    Hi,
    I'm looking for a way to make my workbook non-visible after opening a userform. Upon opening the workbook, I'm running a userform, and I would like to then hide the workbook after the userform opens. I'm currently using Application.Visible = False, but this doesn't seem like a very "safe" way of accomplishing this. Are there any other ways to hide the workbook once the userform opens? Please let me know your thoughts. Thanks!!

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Best way to hide workbook behind userform

    I am presenting this solution, because, like you, I am not absolutely sure
    that making the application invisible when opening a userform is safe.
    I am willing to learn if someone has a method that works for any Excel workbook,
    and the application will never fail to regain its visibility.

    Here is what I found to work in Excel 2003 to remove Excel from view without making
    it invisible. I made the Excel application window smaller than the user form, and
    positioned the Excel window so that the form covers it up. You can see the Excel
    window if you drag the form away from it. A file is attached to test this.

    Add this code to a new module. Edit the properties so that the Excel window
    boundaries are within the boundaries of the user form.
    Please Login or Register  to view this content.
    Add this code to the form's Terminate event:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Best way to hide workbook behind userform

    Thanks xlJer! I haven't tried out your code yet...I kind of screwed up and made my workbook invisible upon open, but then I had the workbook coded to close on terminating the userform so now I can't access my workbook or code lol! Luckily I have a backup somewhere. You've presented a clever idea and I'm going to work with it when I get the time. Have you tried Application.WindowState = xlMinimized? I was having issues with it last night, it minimized xl on open, but I had to click on the window in the taskbar to get my userform to show. Was wondering if you've tried xlMinimized and experienced the same thing?

  4. #4
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Best way to hide workbook behind userform

    For my version of Excel, Application.WindowState can be used to hide or
    show the Excel window and still have the form in view if I set the form's
    ShowModal property to False. If ShowModal is set to True then the form starts
    out on the taskbar.

    Changing ShowModal to False is probably a very poor option, and there is
    some wise guru who can tell you why its not good to lose control of your form while it is open.

    Edit: open Excel, hold the Shift key down and open the problem workbook to bypass the auto-open code.
    Last edited by xLJer; 12-03-2012 at 07:18 PM.

  5. #5
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Best way to hide workbook behind userform

    Here is another way that leaves the Excel window on your taskbar and just
    a form on the screen. This time, what is behind the form is invisible.

    The attached file uses two forms--one non-modal form whose mission is just to
    open the main form which is modal. In the Activate event of the non-modal form,
    the code executes a "Me.Hide" and then opens the main form.
    The module that I used in the previous file download provides the Application.WindowState
    commands to put the Excel window on the taskbar, and restore it when done.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Best way to hide workbook behind userform

    Thanks xlJer, while I haven't found the "pefect" solution yet, I have gotten a little creative and almost have my userform functioning the way I'd like it to. Thanks for providing your input, I appreciate it

  7. #7
    Registered User
    Join Date
    07-13-2010
    Location
    Allentown, Pa, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Best way to hide workbook behind userform

    You can also try Application.Left = -999
    This will position the workbook off screen.

  8. #8
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Best way to hide workbook behind userform

    Quote Originally Posted by VBA FTW View Post
    Thanks xlJer! I haven't tried out your code yet...I kind of screwed up and made my workbook invisible upon open, but then I had the workbook coded to close on terminating the userform so now I can't access my workbook or code lol! Luckily I have a backup somewhere.
    When you keep the shift button pressed while opening your workbook the workbook_open event will not be executed and you will be able to access your code without any problems
    If you like my contribution click the star icon!

  9. #9
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Best way to hide workbook behind userform

    Quote Originally Posted by Olaf.Braxhoofden View Post
    When you keep the shift button pressed while opening your workbook the workbook_open event will not be executed and you will be able to access your code without any problems
    Really? That's awesome, thanks for the tip!

  10. #10
    Registered User
    Join Date
    10-18-2008
    Location
    michigan
    MS-Off Ver
    2010
    Posts
    88

    Re: Best way to hide workbook behind userform

    Happy New Year:

    What i do is have my userform pop up in sheet one when I open the workbook, and have my data in sheet two. I also format the fill color of the cells behind the userform.
    At one time the userform would open in a blank workbook then open the proper workbook when a selection was made. I changed because I got confused when i wanted to add selections and didn't use the exact syntax for the path and file name.

    Mike

  11. #11
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Best way to hide workbook behind userform

    Although my 2-form suggestion was probably not the one used, I did come across a
    unique way to use it to hide Excel while a user form is open.

    Userform1 is non-modal and set to 800 height, 1200 width. I made a screenshot of
    an Excel screen with a blank worksheet, and used this image to entirely fill Userform1. The
    form's Zoom property can also be used to get the desired visual effect.

    As in my example, the code in non-modal Userform1 opens modal Userform2, and the background
    filling the entire screen is just an image.

  12. #12
    Registered User
    Join Date
    01-08-2014
    Location
    Van Buren, AR
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Best way to hide workbook behind userform

    I have to say that this worked perfectly for what I wanted to do.. lol.. I've been searching for days all over the internet on something like this and even found a forum talking about UserForms not being in the taskbar is a known bug, yada yada.. and here you've found a completely safe way to do this!!!

    Quote Originally Posted by xLJer View Post
    I am presenting this solution, because, like you, I am not absolutely sure
    that making the application invisible when opening a userform is safe.
    I am willing to learn if someone has a method that works for any Excel workbook,
    and the application will never fail to regain its visibility.

    Here is what I found to work in Excel 2003 to remove Excel from view without making
    it invisible. I made the Excel application window smaller than the user form, and
    positioned the Excel window so that the form covers it up. You can see the Excel
    window if you drag the form away from it. A file is attached to test this.

    Add this code to a new module. Edit the properties so that the Excel window
    boundaries are within the boundaries of the user form.
    Please Login or Register  to view this content.
    Add this code to the form's Terminate event:
    Please Login or Register  to view this content.

+ 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