ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File name (https://www.excelbanter.com/excel-programming/433848-file-name.html)

fi.or.jp.de

File name
 
I have userform, where combobox need show the file names.

Suppose i have opened 5 excel files as A.xlsx, B.xlsx, C.xlsm, D.xlsx,
E.xlsx

All the 5 files names should be available in Combo Box.

Thanks in advance

Barb Reinhardt

File name
 
Try something like this

Private Sub UserForm_Initialize()
Dim WB As Excel.Workbook

For Each WB In Application.Workbooks
'Change UserFormName to the name of your user form. Also change the
Combobox name as needed
UserformName.Controls("Combobox1").AddItem (WB.Name)
Next WB
Me.ComboBox1.Text = "Select a workbook."

End Sub

Keep in mind that this will work for all workbooks opened in the current
excel instance. If workbooks are opened in another excel instance, they
won't be seen.

HTH,
Barb Reinhardt

"fi.or.jp.de" wrote:

I have userform, where combobox need show the file names.

Suppose i have opened 5 excel files as A.xlsx, B.xlsx, C.xlsm, D.xlsx,
E.xlsx

All the 5 files names should be available in Combo Box.

Thanks in advance


fi.or.jp.de

File name
 
Thanks Barb, Works fine.

As you said what i should do if the user opened in another excel ??

Any Alternate solution.


On Sep 20, 12:52*am, Barb Reinhardt
wrote:
Try something like this

Private Sub UserForm_Initialize()
* *Dim WB As Excel.Workbook

* *For Each WB In Application.Workbooks
* * * 'Change UserFormName to the name of your user form. *Also change the
Combobox name as needed
* * * UserformName.Controls("Combobox1").AddItem (WB.Name)
* *Next WB
* *Me.ComboBox1.Text = "Select a workbook."

End Sub

Keep in mind that this will work for all workbooks opened in the current
excel instance. *If workbooks are opened in another excel instance, they
won't be seen.

HTH,
Barb Reinhardt

"fi.or.jp.de" wrote:
I have userform, where combobox need show the file names.


Suppose i have opened 5 excel files as A.xlsx, B.xlsx, C.xlsm, D.xlsx,
E.xlsx


All the 5 files names should be available in Combo Box.


Thanks in advance



smartin

File name
 
fi.or.jp.de wrote:
I have userform, where combobox need show the file names.

Suppose i have opened 5 excel files as A.xlsx, B.xlsx, C.xlsm, D.xlsx,
E.xlsx

All the 5 files names should be available in Combo Box.

Thanks in advance


Try this

Private Sub UserForm_Initialize()
Dim wb As Workbook
For Each wb In Application.Workbooks
ComboBox1.AddItem wb.Name
Next
End Sub


All times are GMT +1. The time now is 02:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com