'Code in Form
Private fl As Boolean
Private nFld As String
Private Sub ComboBox1_Change()
If Not fl Then
fl = True
If Not InStr(1, nFld, ComboBox1) > 0 Then
ComboBox1 = nFld & ComboBox1 & "\"
End If
nFld = ComboBox1
Call GetSubFolderNames(ComboBox1, ComboBox1)
Call GetFileNames(ListBox1, ComboBox1)
fl = False
End If
End Sub
Private Sub UserForm_Initialize()
fl = True
nFld = "C:\"
ComboBox1 = nFld
Call GetSubFolderNames(ComboBox1, ComboBox1)
Call GetFileNames(ListBox1, ComboBox1)
fl = False
End Sub
'######################### Get Data Explorer ######################
Private Sub GetSubFolderNames(cmBx As Variant, NameFolder As String)
On Error GoTo iExit
Dim MyFSO As Object
Dim MyFile As Object
Dim MyFolder As Object
Dim MySubFolder As Object
Set MyFSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = MyFSO.GetFolder(NameFolder)
cmBx.Clear
For Each MySubFolder In MyFolder.SubFolders
cmBx.AddItem MySubFolder.Name
Next
iExit:
End Sub
Sub GetFileNames(lstBx As Variant, NameFolder As String)
On Error GoTo iExit
Dim MyFSO As Object
Dim MyFile As Object
Dim MyFolder As Object
Set MyFSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = MyFSO.GetFolder(NameFolder)
lstBx.Clear
For Each MyFile In MyFolder.Files
If InStr(1, MyFile.Name, "ice") > 0 Then
lstBx.AddItem MyFile.Name
End If
Next MyFile
iExit:
End Sub