+ Reply to Thread
Results 1 to 15 of 15

Show Userform Behind Active Windows

  1. #1
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Exclamation Show Userform Behind Active Windows

    Hello,

    I currently have a userform that always remains on top of other excel workbooks (unless opened in another instance of excel). How can I make the userform move to the background when another workbook is activated, and automatically come back on top when the sheet with the userform is selected again?

    Thanks
    surge

  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: Show Userform Behind Active Windows

    Hello surge,

    Set the UserForm.ShowModal property to False.
    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
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Show Userform Behind Active Windows

    The setting is marked as false, but the userform still remains above other workbooks

    I made this change in the properties window on the left side of the object editor...does that make a difference?

  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: Show Userform Behind Active Windows

    Hello gsurge,

    I believe I have misunderstood you. When you say workbook, are you referring to the Excel file that is open or a worksheet in that file?

  5. #5
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Show Userform Behind Active Windows

    Any other workbook or even worksheet that is open (in the same instance of excel) will always appear behind the open userform box...

  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: Show Userform Behind Active Windows

    Hello gsurge,

    Thanks, I understand the problem now. I can provide you with code to make the UserForm behave like a window: Minimize, Maximize, Restore. Would that be an option of interest?

  7. #7
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Show Userform Behind Active Windows

    yes i would appreciate that. thank you

  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: Show Userform Behind Active Windows

    Hello gsurge,

    Here is the code. Copy this into a separate VBA module in your workbook. You will need to call the macro twice from the UserForm. There is an example below the macro code.
    Please Login or Register  to view this content.

    Example of Using the Macro on a UserForm
    Copy this code to the UserForm.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Show Userform Behind Active Windows

    This is perfect! Thanks so much

  10. #10
    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: Show Userform Behind Active Windows

    Hello gsurge,

    You're welcome. Glad you didn't have any problems installing or running the code.

  11. #11
    Registered User
    Join Date
    02-05-2015
    Location
    pune,India
    MS-Off Ver
    2010
    Posts
    2

    Re: Show Userform Behind Active Windows

    Hi Leith,

    I tried to use the code that you provided above. But, it doesn't seem to work for me. I am using excel 2007.

    i have coded this code in activate event of my userform abd coped the code in one Module. Acticate event is called when i do a show userform and code executed successfully. But the buttons are not added. Could you please help me here.

    Private Sub UserForm_Activate()
    AddToForm MIN_BOX
    AddToForm MAX_BOX
    End Sub

  12. #12
    Registered User
    Join Date
    02-05-2015
    Location
    pune,India
    MS-Off Ver
    2010
    Posts
    2

    Re: Show Userform Behind Active Windows

    Hi Leith,

    Somehow this seems to be working now. I am able to minimize my userform and open other excel sheets. I have changed the userform to vbmodless. Thanks for the code !! However, i have a question here : If i open another excel worksheet when the userform is minimized, the userform gets maximized by itself. Then again i have to minimize it. Is there a way to handle it ?

    Quote Originally Posted by samirsingh View Post
    Hi Leith,

    I tried to use the code that you provided above. But, it doesn't seem to work for me. I am using excel 2007.

    i have coded this code in activate event of my userform abd coped the code in one Module. Acticate event is called when i do a show userform and code executed successfully. But the buttons are not added. Could you please help me here.

    Private Sub UserForm_Activate()
    AddToForm MIN_BOX
    AddToForm MAX_BOX
    End Sub

  13. #13
    Registered User
    Join Date
    03-05-2021
    Location
    Brazil
    MS-Off Ver
    19
    Posts
    2

    Re: Show Userform Behind Active Windows

    All declares in my excel module is in error, because all are with font red as this one
    Private Declare Function SetWindowLong _
    Lib "user32.dll" _
    Alias "SetWindowLongA" _
    (ByVal hwnd As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long

  14. #14
    Registered User
    Join Date
    09-21-2015
    Location
    Kansas City
    MS-Off Ver
    10
    Posts
    1

    Re: Show Userform Behind Active Windows

    You must be running a 64 bit version. Add SafePtr between Declare and Function then change Long to LongPtr

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Show Userform Behind Active Windows

    Quote Originally Posted by alvaroramos View Post
    All declares in my excel module is in error, because all are with font red as this one
    Private Declare Function SetWindowLong _
    Lib "user32.dll" _
    Alias "SetWindowLongA" _
    (ByVal hwnd As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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