Hi,
I've mixed and matched the code below to allow the user to browse and select a file in any folder. The macro then loads the filename of all files contained in that folder.
The code does not however load file names in the subfolders. Could the formula be amended to include subfolders. Idealy I want the user to select any folder (not a file in any folder) and it will load all the filenames contained in that folder and subfolders. If this was displayed so file path was returned in column A and file names in column B, this would be even better.
*****************************************************
Private Sub Submit_Click()
Dim dlgOpen As FileDialog
Dim vrtSelectedItem As Variant
Dim wsPending As Worksheet
Dim strFile As String
Dim i As Integer
Sheets.Add
ActiveSheet.Name = "Pending"
Set wsPending = Application.ActiveSheet
Set dlgOpen = Application.FileDialog(FileDialogType:=msoFileDialogOpen)
MsgBox "Select any file from the Pending folder"
With dlgOpen
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
strFile = Dir("")
wsPending.Cells(4, 1) = strFile
i = 2
Do
strFile = Dir
wsPending.Cells(i + 3, 1) = strFile
i = i + 1
Loop Until "" = strFile
Next vrtSelectedItem
End If
End With
I've mixed and matched the code below to allow the user to browse and select a file in any folder. The macro then loads the filename of all files contained in that folder.
The code does not however load file names in the subfolders. Could the formula be amended to include subfolders. Idealy I want the user to select any folder (not a file in any folder) and it will load all the filenames contained in that folder and subfolders. If this was displayed so file path was returned in column A and file names in column B, this would be even better.
*****************************************************
Private Sub Submit_Click()
Dim dlgOpen As FileDialog
Dim vrtSelectedItem As Variant
Dim wsPending As Worksheet
Dim strFile As String
Dim i As Integer
Sheets.Add
ActiveSheet.Name = "Pending"
Set wsPending = Application.ActiveSheet
Set dlgOpen = Application.FileDialog(FileDialogType:=msoFileDialogOpen)
MsgBox "Select any file from the Pending folder"
With dlgOpen
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
strFile = Dir("")
wsPending.Cells(4, 1) = strFile
i = 2
Do
strFile = Dir
wsPending.Cells(i + 3, 1) = strFile
i = i + 1
Loop Until "" = strFile
Next vrtSelectedItem
End If
End With