Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I am looking to write a macro that will list the contents of a
specified folder, including the contents of subfolders. Is this something that i can do with a macro? Thanks. Asa |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
It would help if you mapped the folder that you want to list out to a drive.
I do this as follows: Start - Run - cmd I have multiple drives mapped. Let's say I want to get a listing of the Y drive. I type in Y: I then type: dir/s z:textfile.txt It will save a listing of the Y drive on my Z drive as a file named textfile.txt Good luck. " wrote: I am looking to write a macro that will list the contents of a specified folder, including the contents of subfolders. Is this something that i can do with a macro? Thanks. Asa |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() Change strPath to the desired folder. Listing added to Column B of active sheet. -- Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware Sub ListAllFilesInFolder() 'Jim Cone - San Francisco - Oct 2006 Dim strPath As String Dim oFSO As Object Dim oFile As Object Dim oFolder As Object Dim N As Long N = 1 strPath = "C:\Documents and Settings\Name\My Documents\Excel Files" 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 Call ListSubFolderFiles(oFolder, N) Set oFSO = Nothing Set oFile = Nothing Set oFolder = Nothing End Sub Function ListSubFolderFiles(ByRef oParentFolder As Object, ByRef lngR As Long) Dim oSubFolder As Object Dim oFile As Object For Each oSubFolder In oParentFolder.SubFolders Cells(lngR, 1).Value = oSubFolder.Path Range(Cells(lngR, 1), Cells(lngR, 5)).Interior.ColorIndex = 15 lngR = lngR + 1 For Each oFile In oSubFolder.Files Cells(lngR, 2).Value = oFile.Name lngR = lngR + 1 Next ListSubFolderFiles oSubFolder, lngR Next 'oSubFolder End Function '--------------- wrote in message I am looking to write a macro that will list the contents of a specified folder, including the contents of subfolders. Is this something that i can do with a macro? Thanks. Asa |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Followup: Folder listing | Excel Discussion (Misc queries) | |||
How can I insert the contents of a folder into Excel | Excel Discussion (Misc queries) | |||
add a folder to c:\ drive from cell A1 contents... | Excel Discussion (Misc queries) | |||
Periodically listing files in a folder | Excel Discussion (Misc queries) | |||
Listing Directory Contents in Worksheet | Excel Discussion (Misc queries) |