Copy codes of function ShowFolderList into any module, then create unbound listbox with one column on form and RowSourceType=Value List. Put into Form Load procedure this command: Example Private Sub Form_Load() 'List box will be show all folders on drive C:\
me.lstUnboundListBox.RowSource=ShowFolderList("C:\"
End sub
or
Private Sub Form_Load() 'List box will be show all subfolders of folder C:\MyFolder
me.lstUnboundListBox.RowSource=ShowFolderList("C:\MyFolder"
End sub
'---------------------------- Function ShowFolderList(FolderSpec As String) As String 'This function create text for folders listbox (one column)
Dim fs, f, f1, s, sf
Set fs = CreateObject("Scripting.FileSystemObject"
Set f = fs.GetFolder(FolderSpec)
Set sf = f.SubFolders
For Each f1 In sf
If s <> "" Then
s = s & ";"
End If
s = s & f1.Path
Next
ShowFolderList = s
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.