populating a list box or combobox with filenames

ecoscientist

New Member
Joined
Apr 4, 2002
Messages
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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
On 2002-04-05 23:19, ecoscientist wrote:
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

Hi jason

Here is general code to populate a Listbox
with files......

<pre/>

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

</pre>

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.....
 
Upvote 0
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
 
Upvote 0
On 2002-04-06 00:22, Aladin Akyurek wrote:
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

Aladin...yes you can do this...depends what
he really wants to do...doing like this
(not adding to sheet) just skips an extra step......
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,217
Members
448,554
Latest member
Gleisner2

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