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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,215,429
Messages
6,124,838
Members
449,193
Latest member
MikeVol

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