+ Reply to Thread
Results 1 to 12 of 12

Workbook Open event - userform gets displayed over another workbook

  1. #1
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Workbook Open event - userform gets displayed over another workbook

    I have the below code in workbook_Open event for WB1.

    I have two workbooks:
    1. WB1: Has all the buttons and the userforms : this is the front end for the user
    2. WB2: Had all the data tables in various sheets

    When the WB1 is opened, it is supposed to display a userform which has alerts related to some data in a listbox.

    The problem is that this alert userform is displayed over the WB2. How to activate a specific sheet of WB1 to be shown behind the userform.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Workbook Open event - userform gets displayed over another workbook

    You need to post the code that initiates the Userform. The code above makes no reference to a Userform. Also, you refer to WB1 and WB2 and these are not defined anywhere in the post so it is difficult to tell which workbook or worksheet you want to be active when the Userform is displayed.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Workbook Open event - userform gets displayed over another workbook

    Sorry for the confusion. The code in my thread above was in Workbook_Open event for WB1. My objective was to display a userform when this WB1 is opened, The userform would have alerts related to some data in a listbox.

    The second workbook, what I referred to as WB2, is being opened in the above code (the first line after DIM statements).

    However, this code in workbook_open event was causing severe Excel Application problem. When I would open the WB1, Excel would hang. Somehow after ending Excel app from task bar 3-4 times, I got access to the workbook(WB1). I have now removed the code from Workbook_Open event. If you can identify any reason for Excel's crash, do let me know.

    As of now my original problem continues.

    Now I have a button in WK1 which shows the userform and runs the code in userform's initialize event. However, the problem remains. i.e. this userform is displayed over the WB2

    The code now is as follows. Do let me know how to make the form appear on top of WB1, from where the userform is triggered.
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Workbook Open event - userform gets displayed over another workbook

    What I feel is that during the form initialize event, I am opening the DataFile (WB2). And that remains active while the form gets displayed.

    So what code do I write in the code for initialize event, so that the sheet from WB1 becomes the active sheet. I tried Thisworkbook.activate - but it has no impact.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Workbook Open event - userform gets displayed over another workbook

    Hi,

    Try the following code which is included in the attached sample workbook tested in 32 bit Office 365.
    Please Login or Register  to view this content.
    Lewis

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Workbook Open event - userform gets displayed over another workbook

    Since you are calling the UF with a button, you can add a line of code into the macro to make the sheet you want behind the form the active sheet.
    Example:
    Please Login or Register  to view this content.
    The userform would then appear over that sheet.

  7. #7
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Workbook Open event - userform gets displayed over another workbook

    Thanks Lewis.. Your code works for me. I learnt something new in VB with this code.

  8. #8
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Workbook Open event - userform gets displayed over another workbook

    JLGWhiz.. thanks to you too. Your suggestion also works and is much simpler.
    These days I am bit averse of using methods like .Select, as it keeps giving me error in code. But this one works fine.

  9. #9
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Workbook Open event - userform gets displayed over another workbook

    Quote Originally Posted by hemantparmar View Post
    JLGWhiz.. thanks to you too. Your suggestion also works and is much simpler.
    These days I am bit averse of using methods like .Select, as it keeps giving me error in code. But this one works fine.
    I try to stay away from the Select method also, but there are times when it is appropriate to use, and this seemed like one of those times.
    Regards, JLG

  10. #10
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Workbook Open event - userform gets displayed over another workbook

    JLGWhiz, Is there any document giving guidelines on where to use .Select method and where not to?

  11. #11
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Workbook Open event - userform gets displayed over another workbook

    Not specifically. But most books on programming will point the user to direct coding. eg. Parent.Child.Grandchild.Toy where the toy is the object you want to get to rather then Parent.Select
    Child.Select
    Grandchild.Toy

    to get there. Basically, the more you use code and monitor forumns like this one, you will begin to catch on to the compact coding methods and understand how to construct efficient code.

  12. #12
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Workbook Open event - userform gets displayed over another workbook

    See the following short discussion of why Select can and should be avoided most of the time: https://www.excelcampus.com/vba/how-...select-method/

    Lewis

+ 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. [SOLVED] Worksheets arent displayed on workbook open...
    By BuenosDias in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2014, 04:39 AM
  2. Minimise Workbook, Userform to be displayed
    By Rehmat in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-03-2014, 08:18 AM
  3. Workbook Open Event
    By cameron213 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2013, 03:55 AM
  4. Open another workbook for multiple userform event use.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-13-2009, 01:30 AM
  5. Opening workbook without workbook open event
    By davegugg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-16-2009, 05:14 PM
  6. Open workbook via another workbook and not display userform
    By Khaos176 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2009, 02:17 PM
  7. [SOLVED] How to open a workbook with a specific worksheet displayed by defa
    By ThaiNB in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 01-21-2005, 02:07 AM

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