Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list of Files contained in a folder

Status
Not open for further replies.

Westicle

Programmer
Aug 22, 2002
29
GB
How can i get a list of files contained in a particular folder through excel VBA. I.E. i want it to list the file names on a worksheet.
 
This should do the trick

Sub getFilenames()
Dim filename As String, r As Integer, lRow As Integer
'Define variables

filename = Dir$("\\Your\Folder\Path\Goes\Here\*.*")
'Start File Search
Range("A2").Activate

Do While filename <> &quot;&quot;
ActiveCell.Offset(r, 0) = filename
r = r + 1
filename = Dir$()
Loop
End Sub Rgds
~Geoff~
 
Hi
More variations on a theme. This'll also do the trick...

Sub cfc()
Dim fso, fold, f1, phyl, i
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set fold = fso.GetFolder(&quot;C:\&quot;)'or whatever folder/path
Set phyl = fold.Files
i = 0
For Each f1 In phyl
i = i + 1
ActiveSheet.Cells(i, 1).Value = f1.Name
Next

End Sub

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top