![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Location: Jason in Boston MA
Posts: 12
|
If anyone can help me with the creating the code to populate a listbox with all of the files in a given folder, so that a user can select a specific file. Also the number of files changes on a daily basis and the folder accesed can be any one of 3.
THanks Jason |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Here is general code to populate a Listbox with files...... Dim Lb As MSForms.ListBox Dim F Dim x As Integer Set Lb = Me.ListBox1 Lb.Clear F = Dir("C:Excelfiles*.XLS") If F = "" Then MsgBox "Directory doesn't exist!": GoTo Ex Application.ScreenUpdating = False x = 1 On Error GoTo FileErr Do While Len(F) > 0 Lb.AddItem F x = x + 1 F = Dir() Loop GoTo Ex Exit Sub FileErr: MsgBox Err.Number & Chr(13) & _ Err.Description, _ vbMsgBoxHelpButton, _ "File load Error", _ Err.HelpFile, _ Err.HelpContext Ex: Application.ScreenUpdating = True End Sub I suspect that your needsmay be a little diff If you can explain what it is you are doing you may not need to do this..... |
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
|
Ivan,
Why not create the list of files with code, say in a sheet called, Admin and create a dynamic name range, say, FileList for the area where the VBA code creates it. FileList can then be used as source range in a ListBox or Combobox. Aladin |
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
he really wants to do...doing like this (not adding to sheet) just skips an extra step...... |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|