I have a userform with 2 listboxes.
I populate the first listbox with the subfolders in the same folder where de excel file is.
This works
Now I would like to click in Listbox 1 to show the PDF files of the selected folder.in Listbox2
This doesnt'work.
Anybody suggestions?
Thanks in advance.
I populate the first listbox with the subfolders in the same folder where de excel file is.
Code:
Private Sub UserForm_Initialize()
Set FileSystem = CreateObject("Scripting.FileSystemObject")
For Each SubFolder In FileSystem.GetFolder(hostFolder).SubFolders
ListBox1.AddItem SubFolder.Name
Next
Dim File
For Each File In FileSystem.GetFolder(hostFolder).Files
If Right(File.Name, 5) = ".PDF" Then
ListBox1.AddItem File.Name
End If
Next
End Sub
Now I would like to click in Listbox 1 to show the PDF files of the selected folder.in Listbox2
Code:
Private Sub ListBox1_Click()
MyFolder = ThisWorkbook.Path & ListBox1.Column(0)
MyFile = Dir(MyFolder & "\*.PDF")
Do While MyFile <> ""
ListBox2.AddItem MyFile
MyFile = Dir
Loop
End Sub
Anybody suggestions?
Thanks in advance.