Working through files in a directory

N

nath

Hi

Can anyone help me with the code to get a list of the
files and folders in a given path i.e. c:\ and return them
back to an excel sheet.


TIA

Nath
 
B

Bob Phillips

Nath,

One way

Sub CreateFormsListBox()
Dim FSO As Object
Dim oFile As Object
Dim oFiles As Object
Dim oFolder As Object
Dim i As Long
Dim sPath As String

Worksheets.Add.Name = "FileList"

Set FSO = CreateObject("Scripting.FileSystemObject")

sPath = "C:\MyTest"
Set oFolder = FSO.GetFolder(sPath)

Set oFiles = oFolder.Files
For Each oFile In oFiles
i = i + 1
ActiveSheet.Cells(i, "A").Value = oFile.Name
Next oFile

Range("A1").Select

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top