Forum Discussion

clh_1496's avatar
clh_1496
Brass Contributor
Oct 18, 2023
Solved

UserForm with a ComboBox that populates with the name of the open workbooks

Hi,   So I'm looking for some help on creating a UserForm with a ComboBox that populates with the name of the open workbooks and WorkSheets, displays the choices and allows you to select one.   I...
  • HansVogelaar's avatar
    Oct 18, 2023

    clh_1496 

    That code is a macro, to be copied into a standard module (the kind you create by selecting Insert > Module in the Visual Basic Editor).

    Running the macro will populate the combo box, then show the userform.

     

    As an alternative, you could create a UserForm_Initialize event procedure in the userform's module:

    Private Sub UserForm_Initialize()
        Dim book As Workbook, sheet As Worksheet
        For Each book In Workbooks
            For Each sheet In book.Worksheets
                Me.ComboBox1.AddItem book.Name & "!" & sheet.Name
            Next sheet
        Next book
    End Sub

Resources