Filenames into Excel

G

Guest

Using VBA, can anyone tell me know to get all the filenames in a given folder into an Excel spreadsheet. I would like to have each filename in a separate cell. For example, Filename1.txt in A1, Filename2.txt in A2, Filename3.txt in A3, etc. The number of data files (*.txt) will vary each day
Thanks in advance
Lee
 
D

Don Guillett

modify this to suit

Sub FindandListFiles()
Application.ScreenUpdating = False
Columns(1).ClearContents
ThisRow = 2
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim FileLocation As String
FileLocation = "c:\yourfolder\*.txt"
FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub


--
Don Guillett
SalesAid Software
(e-mail address removed)
Lee said:
Using VBA, can anyone tell me know to get all the filenames in a given
folder into an Excel spreadsheet. I would like to have each filename in a
separate cell. For example, Filename1.txt in A1, Filename2.txt in A2,
Filename3.txt in A3, etc. The number of data files (*.txt) will vary each
day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top