I have a function that asks the user to select a folder and then another one that should output all the file names in that folder. I have been trying the following but it does not work because the folder address contains blank spaces. Could you please help?
'gets folder address
recsFolder = Functions.GetFolder("C:\")
'Loop through files in folder
Dim StrFile As String
StrFile = Dir(recsFolder)
Do While Len(StrFile) > 0
Debug.Print StrFile
StrFile = Dir
Loop
Thanks!
Edit: Code for GetFolder
Function GetFolder(strPath As String) As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function
By blank spaces I mean spaces that are present in the address (i.e. between Daily and Summary) C:\Users\User1\Desktop\Daily Summary