#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
I saved file A over file B. Can I get file B back? Lynn Excel Discussion (Misc queries) 2 May 12th 06 11:24 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
I SAVED A FILE OVER ANOTHER A FILE IN EXCEL. THE OLD FILE WAS AN . DUFFER8MCD Excel Discussion (Misc queries) 1 December 23rd 04 11:32 PM
i received a file that reads powerpoint document file file exten. CCAROLACEREC Excel Discussion (Misc queries) 1 December 4th 04 05:02 PM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"