Get name of all xls file open and put in a listbox?

jxb

Board Regular
Joined
Apr 19, 2007
Messages
172
Office Version
  1. 2010
Platform
  1. Windows
To all

I want to create a simple GUI with a listbox and ‘process’ button (done!). In that listbox I want to add the name of all the xls files currently open (in my excel session)

On the processbutton.click I then want to take get the name selected and pass it to a function

1. How do I do that?
2. Is it possible get to the same with multiple selection? Something like that

For Each sFileName As String In asFileNameSelected
Processthedata(sFileName)
Next

Thanks
Regards
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
This simple code will get all open workbooks and enter them into a list box named Listbox1:

Code:
    Dim wb As Workbook
    
    For Each wb In Workbooks
        ListBox1.AddItem wb.Name
    Next wb

Then this code will loop through all items in the list and check if they are selected:

Code:
    For i = 0 To ListBox1.ListCount - 1
        'Check if item is selected
        If ListBox1.Selected(i) Then
            'Run Your code here
        End If
    Next i
 
Upvote 0

Forum statistics

Threads
1,223,987
Messages
6,175,794
Members
452,670
Latest member
nogarth

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