Para quem quiser adaptar...
Pesquisei, pesquisei, adaptei e consegui.
Dim sDiretorio As String
Dim sArquivo As String
Private Sub UserForm_Activate()
Me.ListBox1.Clear
Me.carregarDiretorios
End Sub
Private Sub ListBox1_Click()
Me.ListBox2.Clear
sDiretorio = Me.ListBox1.Value
Me.carregarArquivos
End Sub
Sub carregarDiretorios()
MyPath = "D:Downloads"
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Me.ListBox1.AddItem MyName
End If
End If
MyName = Dir
Loop
End Sub
Sub carregarArquivos()
Dim fileList() As String
Dim fName As String
Dim fPath As String
Dim I As Integer
'define the directory to be searched for files
fPath = "D:Downloads" & sDiretorio & ""
'build a list of the files
fName = Dir(fPath & "*.xlsx")
While fName <> ""
'add fName to the list
I = I + 1
ReDim Preserve fileList(1 To I)
fileList(I) = fName
'get next filename
fName = Dir()
Wend
'see if any files were found
If I = 0 Then
MsgBox "Nenhum arquivo localizado na pasta selecionada!", vbInformation
Exit Sub
End If
'cycle through the list and add to listbox
For I = 1 To UBound(fileList)
Me.ListBox2.AddItem fileList(I)
Next
End Sub
Private Sub CommandButton1_Click()
If Me.ListBox2.Text = "" Then
MsgBox "Selecione um arquivo!", vbCritical
Else
sArquivo = Me.ListBox2.Text
UserForm1.Hide
MsgBox sArquivo
End If
End Sub
Postado : 18/03/2015 6:45 pm