Display files in a directory

  • Thread starter Thread starter Mike D.
  • Start date Start date
M

Mike D.

Hi.

Several months ago, someone posted a quick macro that
would display the files in a given directory. Could
someone point me to that code?

Thanks,
Mike.
 
Sub ListFiles()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Long

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("c:\Test\")
i = 1
With Range("A1")
For Each oFile In oFolder.Files
If oFile.Type = "Microsoft Excel Worksheet" Then
.Cells(i, 1).Value = oFile.Name
i = i + 1
End If
Next
End With
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Thanks, Bob!
-----Original Message-----
Sub ListFiles()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Long

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("c:\Test\")
i = 1
With Range("A1")
For Each oFile In oFolder.Files
If oFile.Type = "Microsoft Excel Worksheet" Then
.Cells(i, 1).Value = oFile.Name
i = i + 1
End If
Next
End With
End Sub


--

HTH

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




.
 
My pleasure.

--

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

Back
Top