Working through files in a directory

  • Thread starter Thread starter nath
  • Start date Start date
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
 
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)
 

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

Similar Threads

Deletion of charts 1
Global vars 1
Enable Macros and Linking sheets 1
Directory Name - IF Named Range Exists 0
Reading Directories 3
Clearing Combo Boxes. 2
Printing 3
List boxes 1

Back
Top