When I use Windows File Directory, I can see the listings of a directory or sub directory showing such data as file name, file type and other file information. How can I input that information into an Excel spreadsheet?
When I use Windows File Directory, I can see the listings of a directory or sub directory showing such data as file name, file type and other file information. How can I input that information into an Excel spreadsheet?
Well here is a macro that you can use to navigate to a specific directory and then select it and list all files within it including their extensions.
Option Explicit
Sub GetFileNames()
Dim xRow As Long
Dim xDirect, xFname
Dim Dest As Range
'Change this to put the data in a different place in the workbook.
Set Dest = ActiveCell
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Select a folder"
.Show
If .SelectedItems.Count <> 0 Then
xDirect = .SelectedItems(1) & "\"
xFname = Dir(xDirect, 7)
Do While xFname <> ""
Dest.Offset(xRow) = xFname
xRow = xRow + 1
xFname = Dir
Loop
End If
End With
End Sub