I am using Application.FileDialog(msoFileDialogFilePicker)
and navigating to any specific folder to automatically select (and highlight if possible) all files in that folder, populating the Filename
textbox in Application.FileDialog
as shown below (here i have only manually selected 2 files for populating the filename textbox:
I tried:
Sub SelectAllFilesInFolder()
Dim fd As FileDialog
Dim vSelectedItems As Variant
Const sPath As String = "C:\Users\somefolder\"
Dim sFileString As Variant
Dim vFiles As Variant
Dim FileColl As Collection
With ThisWorkbook
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = True
.Filters.Add "Word Files", "*.doc*", 1
.InitialFileName = sPath
.ButtonName = "Select"
sFileString = sPath & Chr(31) & "France - Charlotte.docx" & Chr(31) & " " & Chr(31) & "France - Fabienne.docx" & Chr(31)
.InitialFileName = sFileString
If .Show = -1 Then
' some processing code
End If
End With
End With
End Sub
However, initialFilename
is not populating the filename
textbox. Even if i manually enter the following string in it, it gives an error on clicking Open button.
"France - Charlotte.docx" "France - Fabienne.docx"
It seems the string that gets populated when user manually selects files in folder, is different somehow. How can this be automated?