How do I display all the filename in a folder in excel ?

E

Eng Teng

How do I display all the filename in a folder in excel ?
Example : In c:\abc folder got filename file1.txt , file2.txt and file3.txt

How do I display in excel in the following order :-
c:\abc\file1.txt
c:\abc\file2.txt
c:\abc\file3.txt

Regards,
Tee
 
J

Jim Cone

Sub ListAllFilesInFolder()
'Jim Cone - Portland Oregon - USA
Dim strPath As String
Dim oFSO As Object
Dim oFile As Object
Dim oFolder As Object
Dim N As Long

strPath = "C:\Program Files\Microsoft Office\Office11"

N = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strPath)
Cells(N, 1).Value = oFolder.Path
N = N + 1
For Each oFile In oFolder.Files
Cells(N, 2).Value = oFile.Name
N = N + 1
Next 'oFile
Set oFSO = Nothing
Set oFile = Nothing
Set oFolder = Nothing
End Sub
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins - free trial of "List Files" - no registration)




"Eng Teng"
wrote in message
How do I display all the filename in a folder in excel ?
Example : In c:\abc folder got filename file1.txt , file2.txt and file3.txt
How do I display in excel in the following order :-
c:\abc\file1.txt
c:\abc\file2.txt
c:\abc\file3.txt
Regards,
Tee
 

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