Populate combobox with all open workbook names?

jkeyes

Active Member
Joined
Apr 15, 2003
Messages
343
Does anyone have some quick code for populating a combobox with the full names (i.e. wkbk1.xls) of all open workbooks?

Thanks for any and all help!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hello,
Code:
Dim wkb As Workbook
For Each wkb In Workbooks
    If wkb.Visible Then
        YourComboBox.Items.Add(wkb.Name)
    End If
Next wkb
Set wkb = Nothing
The visible check is because you want to, presumably, skip Personal.xls, etc. Good Luck!
 
Upvote 0
Thanks for the reply, and sorry for the delay (this project got put on hold)...

So I tried your code... I put it under the Sheet selection Change event, added a Control ComboBox to the sheet, and named it cbOpenFiles (I adjusted the code for this):

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim wkb As Workbook
    For Each wkb In Workbooks
        If wkb.Visible Then
            cbOpenFiles.Items.Add (wkb.Name)
        End If
    Next wkb
    Set wkb = Nothing
End Sub

But, I'm getting a Run-time Error 438, Object doesn't support this property or method, and the debugger is highlighting the If wkb.Visible line.

Also, I meant to ask that the name of this current workbook be excluded from the ComboBox list...

Any ideas on what I'm doing wrong or need to do to fix? Thanks again!
 
Upvote 0
Sorry, you have to iterate the Windows collection instead of the Workbooks collection. I usually work with the Sheets collection and I always forget this :(.
Code:
Dim win As Window
For Each win In Windows
    If win.Visible = True Then
        If win.Parent.Name <> ActiveWorkbook.Name Then
            ' Do your processing here
            cbOpenFiles.Items.Add win.Parent.Name
        End If
    End If
Next Window
Set win = Nothing
Good Luck!
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top