Hi I love this code but there are times when i don't want the user to actually pick a folder. At the moment when running the code you are prompted to "select a folder to list files from" I want to hard code in the folder name so at the click of a button it will show all the current files in C drive. Can anyone help please. I have tried different codes but this is the most user friendly as it shows the files names very quickly. I hope this makes sense
Regards
Christine
Sub GetFileNames()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "C:\"
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub
Bookmarks