Generate list of folders in given Dir

  • Thread starter Thread starter john q public
  • Start date Start date
J

john q public

Hi all i am trying to fill a combobox with the names of folders in 26
different directories using the following code


MyPath = "q:\orders\a\" ' Set the path.
myname = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While myname <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If myname <> "." And myname <> ".." Then
ComboBox1.AddItem myname
If (GetAttr(MyPath & myname) And vbDirectory) = vbDirectory
Then


End If
End If
myname = Dir Loop

my path canges from a,b,c,d,e,f..........z and the code i have here
does the job however it takes about 1 minute for it to run all the
loops and fill the combobox.

Is there anyway this can be done quicker?
 
Set a reference to the Microsoft Scripting Runtime:

Sub Tester1()
Dim fso As New FileSystemObject
Dim fld As Folder
Dim tFld As Folder
Dim sFol As String
sFol = "C:\"
Set fld = fso.GetFolder(sFol)
i = 0
For Each tFld In fld.SubFolders
i = i + 1
Cells(i, 1).Value = tFld.Name
Next
End Sub
 
Back
Top