-
Reading folder names and populating listbox
Does anyone know of a good way to read file system folders and populate a listbox with these names? I am currently using the following lines of code to do this and it works. However, it is very sluggish and was wandering what a better way to do this would be. Here is the code I am using:
[VBA]Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(\\ohlew0010\plis\map83)
Set fc = f.Subfolders
For Each f1 In fc
'following line adds folder names to cmbStates listbox
cmbStates.AddItem (f1.Name)
Next[/VBA]
Any help is greatly appreciated!!
-
File Scripting Object is what I use. You can try using Early Binding instead of Late Binding. Set a reference to the Microsoft Scripting Runtime (Tools | References).
Then instead of using CreateObject just use New.
[vba]
Set fs = New FileSystemObject[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules