+ Reply to Thread
Results 1 to 12 of 12

I need VBA code to make each combobox option on a userform open an excel workbook ...

  1. #1
    Registered User
    Join Date
    09-22-2014
    Location
    Wellingborough, England
    MS-Off Ver
    Microsoft Office 2016 Professional
    Posts
    49

    Smile I need VBA code to make each combobox option on a userform open an excel workbook ...

    Hi ... I'm new to VBA Coding but I am trying to get a userform with a combobox to open different excel workbooks when an item is selected and the command button is clicked.
    The options on the combobox are as follows ...

    QTR1 to open "Workbook A"
    QTR2 to open "Workbook B"
    QTR3 to open "Workbook C"
    QTR4 to open "Workbook D"
    Daily Audits Completed QTR1 to open "Workbook E"
    Daily Audits Completed QTR2 to open "Workbook F"
    Daily Audits Completed QTR3 to open "Workbook G"
    Daily Audits Completed QTR4 to open "Workbook H"

    I hope someone out there can help.

    Many thanks in anticipation ....
    Last edited by Jalica; 09-15-2016 at 03:20 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 2502
    Posts
    26,779

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    I suggest that you add an "Open" button rather than opening the file as soon as the user makes a selection. Users can make mistakes. This is the code for the OK button. You put this code in the module for the userform. I have compiled but not tested this, as I would have to create the form and all these files:
    Please Login or Register  to view this content.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-22-2014
    Location
    Wellingborough, England
    MS-Off Ver
    Microsoft Office 2016 Professional
    Posts
    49

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    Many Thanks ....

    It sort of works.
    When I click on the command button it opens up the new workbook and closes the userform on the original workbook and leaves that workbook open (which is what I want) but the new workbook is unresponsive (inactive) when it opens.

    How do I make the new workbook active when it opens? ...

    Edit: ** I've just noticed that when the new workbook opens as unresponsive (inactive), if I click back onto the original workbook with the userform, then click back onto the new workbook it becomes responsive (active) **
    Last edited by Jalica; 09-15-2016 at 06:19 AM.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,779

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    Inactive and unresponsive mean two completely different things. Do you mean that the file opens but does not have focus? Or do you mean that the file opens but does not respond to any user input?

    I have not tested this but this form of the command may solve it:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If you continue to have problems I will try to set up a test.

  5. #5
    Registered User
    Join Date
    09-22-2014
    Location
    Wellingborough, England
    MS-Off Ver
    Microsoft Office 2016 Professional
    Posts
    49

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    I appreciate your time and effort but that didn't work.

    I have "Workbook 1" which has a userform (combobox) on it. The userform opens other "Workbooks A to H" depending on what is selected in the userform and after open file is clicked.

    By unresponsive I mean that when the new "Workbook A" initially opens, no items on the menu bar work (File, Home, Insert, Page Layout, etc).
    But if I click back onto the original "Workbook 1" with the userform the menu items on that workbook work OK...
    I then click back onto the new "Workbook A" again and the menu items now work Ok as well.

    I've tried it with Unload Me in the code and without Unload Me in the code but that makes no difference.

    I hope I've explained my problem clearly now.
    I've pasted the code I have so far below ...



    Private Sub cbFiles_Change()

    Image1.Picture = LoadPicture(ThisWorkbook.Path & "\" & cbFiles.Value & ".jpg")

    End Sub

    Private Sub cmdOpen_Click()

    If cbFiles.Value = "" Then
    If MsgBox("You have not selected anything yet. If you continue this selection box will close. Do you want to continue?", vbQuestion + vbYesNo) <> vbYes Then
    Exit Sub
    End If
    End If

    Select Case Me.cbFiles
    Case "QTR1"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook A.xlsx").Activate
    Case "QTR2"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook B.xlsx").Activate
    Case "QTR3"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook C.xlsx").Activate
    Case "QTR4"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook D.xlsx").Activate
    Case "Daily Audits Completed QTR1"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook E.xlsx").Activate
    Case "Daily Audits Completed QTR2"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook F.xlsx").Activate
    Case "Daily Audits Completed QTR3"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook G.xlsx").Activate
    Case "Daily Audits Completed QTR4"
    Workbooks.Open(Filename:="C:\Users\Paul\Documents\Workbook H.xlsx").Activate
    End Select

    Unload Me

    End Sub

    Private Sub cmdClose_Click()

    Unload Me

    End Sub
    Last edited by Jalica; 09-15-2016 at 12:44 PM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    Try putting Unload Me before the code that opens the workbook(s).

    PS Can you add code tags when posting code?
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    09-22-2014
    Location
    Wellingborough, England
    MS-Off Ver
    Microsoft Office 2016 Professional
    Posts
    49

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    Tried putting Unload Me before code that opens workbook with NO luck

    Apologies .... I had wondered how you got the code into those boxes

    Please Login or Register  to view this content.
    Regards ...

    Paul Norris

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,779

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    I was able to resolve this by setting the ShowModal property of the form to False in the form properties.

  9. #9
    Registered User
    Join Date
    09-22-2014
    Location
    Wellingborough, England
    MS-Off Ver
    Microsoft Office 2016 Professional
    Posts
    49

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    You're an absolute superstar .... Works a treat.
    Thank you so much for your time and effort

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,779

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    You are welcome! I should explain, since you said you are new at VBA. When a Modal form is shown in Excel, you cannot do anything else in Excel while that form is displayed. But if it is modeless (ShowModal = False) you can continue to do anything else on worksheets or other forms. In more complicated Excel applications these should be managed with great care but your case looks rather simple.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,779

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon below their name.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: I need VBA code to make each combobox option on a userform open an excel workbook ...

    In the code in post #7 the Unload Me is still after the code to open the workbook(s).

    This is what I meant.
    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)

Similar Threads

  1. Populating ComboBox based on Option button in excel userform
    By dotchiejack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2016, 07:41 AM
  2. how to make workbook open code specific to a sheet
    By whitwoo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-18-2014, 01:16 PM
  3. Returning the row number of the option after the selected option in a userform combobox
    By rep67439fgs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2014, 08:07 AM
  4. UserForm help - display list of open workbooks except workbook userform code is in
    By kensweep in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-09-2014, 12:26 PM
  5. [SOLVED] Make combobox list options dependant on selection in another combobox within a userform
    By Vladimir_Dobvchenko in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-23-2013, 05:30 AM
  6. [SOLVED] Open UserForm when workbook opens (and not the code editor)
    By GavJ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2013, 02:12 AM
  7. [SOLVED] Wanna make a Userform Close and Save - Then open a different workbook?
    By Wanting2Excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-06-2012, 08:29 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