Hello,
It's me again, can anyone help me modify this code.
My aim is to list all the folders with its subfolders. I have 3 locations/directories that need to be listed.
I put all the locations on the same workbook (it's on sheet2("folder_path").
The sheet serves as my database for path and owner name (I can still add new locations and names on this sheet.
Can anyone help me please.
Someone sent me this code but I can't modify it to add my other 2 location.
here's the code:
===========================================
Sub CreateList()
Application.ScreenUpdating = False
ThisWorkbook.Worksheets.Add
With Cells(1, 1)
.Value = "Folder contents of:"
.Font.Bold = True
.Font.Size = 11
End With
'Cells(3, 1).Value = "Owner:"
Cells(4, 1).Value = "Folder Name:"
Cells(4, 2).Value = "Size:"
Cells(4, 3).Value = "Subfolders:"
Cells(4, 4).Value = "Files:"
Cells(4, 5).Value = "Date Modified:"
Cells(4, 6).Value = "Date Created:"
Range("A4:F4").Font.Bold = True
ListFolders (Worksheets("folder_path").Cells(1, 1).Value), True
'ListFolders (Worksheets(2).Cells(2, 1).Value), True
Application.ScreenUpdating = True
End Sub
Sub ListFolders(SourceFolderName As String, IncludeSubfolders As Boolean)
' lists information about the folders in SourceFolder
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
' display folder properties
r = Cells(Rows.Count, 1).End(xlUp).Row + 1
'Cells(r, 1).Value = SourceFolder.ParentFolder
Cells(r, 1).Value = SourceFolder.Name
Cells(r, 2).Value = SourceFolder.Size
Cells(r, 3).Value = SourceFolder.SubFolders.Count
Cells(r, 4).Value = SourceFolder.Files.Count
Cells(r, 5).Value = SourceFolder.DateLastModified
Cells(r, 6).Value = SourceFolder.DateCreated
With Cells(2, 1)
.Value = (Worksheets("folder_path").Cells(1, 2).Value)
End With
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFolders SubFolder.Path, True
Next SubFolder
Set SubFolder = Nothing
End If
Columns("A:F").AutoFit
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = False
End Sub
==============================================
These are the contents of sheet "folder_path".
C:\Documents and Settings\administrator\Desktop\fileinfo_test\ Celestino
C:\Documents and Settings\administrator\Desktop\fileinfo_test\testing\ Ryan
C:\Documents and Settings\administrator\Desktop\laptop-mheds\antivirus\Symantec\cd2\ Ruel
Looking forward that somebody will help me.
Thank you in advance..
mhel
Configuration: Windows XP Internet Explorer 6.0