PDA

View Full Version : [SOLVED:] VBA myFSO GetFolder path problem



DeanP
12-21-2018, 03:19 PM
I am trying to get a list of files in a folder using GetFolder.

I have declared myFolder as below, now I want to set my folder with MyFSO.GetFolder("______")

My folder path is in a text box (TextBox5) in the userform. How do I reference that text box in my macro?


Dim MyFSO As FileSystemObject
Dim MyFile As File
Dim MyFolder As Folder
Set MyFSO = New Scripting.FileSystemObject
Set MyFolder = MyFSO.GetFolder(??)

Paul_Hossler
12-21-2018, 03:33 PM
If I'm understanding





Set MyFolder = MyFSO.GetFolder(UserForm1.TextBox5.Text)

Kenneth Hobs
12-21-2018, 04:13 PM
Add /s if you want subfolder files too.

Private Sub UserForm_Initialize()
TextBox5.Value = "C:\myfiles\Excel\pdf"
End Sub


Private Sub CommandButton1_Click()
ListBox1.List = Filter(Split(CreateObject("wscript.shell").exec("cmd /c Dir " & _
"""" & TextBox5.Value & """" & " /b / a-d").stdout.readall, vbCrLf), ".")
End Sub