listing files


Posted by stevie windows on July 17, 2001 6:15 AM

How can I list the files in a folder on an Excel Worksheet?

Posted by Loren on July 17, 2001 6:32 AM

Listing files from a directory
puts the files in Column A,starting with A1.

Sub trythis()
Dim Path As String

Range("A1:A65000").ClearContents
Path = InputBox(prompt:="Enter the path of the folder to search:", Title:="Mrexcel.com")
With Application.FileSearch
.NewSearch
.LookIn = Path
.SearchSubFolders = True ' change as needed
.FileName = "*" ' Change as needed
.MatchAllWordForms = True
.FileType = msoFileTypeAllFiles ' change as needed
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1) = .FoundFiles(i) ' results in cell A[1-n]
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
'I forget who posted this initially

Posted by stevie windows on July 17, 2001 6:37 AM

This helps, and I might be able to figure it out from this code. I don't want to search for files, rather to just list the files in a directory, with a different file name in each cell.



Posted by stevie windows on July 17, 2001 6:45 AM

Done it.