I found this code on this forum a while ago.
Code
Sub ShowFileList()
Dim fs, f, f1, s, sf, iRow, dir
Set fs = CreateObject("Scripting.FileSystemObject")
dir = InputBox("What directory would you like the list generated from?")
Set f = fs.GetFolder(dir)
Set sf = f.Files
iRow = 3
For Each f1 In sf
'Cells(iRow, 1) = Left(f1.Name, Len(f1.Name) - 4)
Cells(iRow, 1) = f1.Name
Cells(iRow, 2) = f1.Size
iRow = iRow + 1
Next
End Sub
Display More
I tried to change it where you get the GetOpenFilename pop-up box and make a choice from it instead of entering the path in an input box. However, whatever I tried did not work. I get the pop-up box OK but all I get is that I did not select a file.
Code
Sub ShowFileListA()
Dim fs, f, f1, s, sf, iRow, dir
Set fs = CreateObject("Scripting.FileSystemObject")
ChDir "C:\"
dir = Application.GetOpenFilename '(filefilter:="AllFiles.(*.*),*.*,All Files (*.*),*.*")
If f = False Then
MsgBox "You didn't select a folder"
Exit Sub
End If
Set f = fs.GetFolder(dir)
Set sf = f.Files
iRow = 3
For Each f1 In sf
Cells(iRow, 1) = Left(f1.Name, Len(f1.Name) - 4)
Cells(iRow, 2) = f1.Size
iRow = iRow + 1
Next
End Sub
Display More
Could someone show me where I went wrong.
Thanks and regards
John