mohamedtaha500
New Member
hello every one
i use this code to bring files's name have .doc from exact folder and subfolder from path which i put in code and put the data in excel sheet
the code is work great
but the problem is i need also date modified for every file but i can't edit on code
i use this code to bring files's name have .doc from exact folder and subfolder from path which i put in code and put the data in excel sheet
the code is work great
but the problem is i need also date modified for every file but i can't edit on code
Code:
Sub ListAllFilesInAllFolders()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim MyPath As String, MyFolderName As String, MyFileName As String
Dim i As Integer, F As Boolean
Dim objShell As Object, objFolder As Object, AllFolders As Object, AllFiles As Object
Dim MySheet As Worksheet, rrr As Long
On Error Resume Next
lastrow = Sheet2.Range("a" & Rows.Count).End(xlUp).Row
Sheet2.Range("a2", "a" & lastrow + 1).ClearContents
MyPath = Sheet1.Cells(2, 1).Value & "\"
Set objFolder = Nothing
Set objShell = Nothing
Set AllFolders = CreateObject("Scripting.Dictionary")
Set AllFiles = CreateObject("Scripting.Dictionary")
AllFolders.Add (MyPath), ""
i = 0
Do While i < AllFolders.Count
Key = AllFolders.keys
MyFolderName = Dir(Key(i), vbDirectory)
Do While MyFolderName <> ""
If MyFolderName <> "." And MyFolderName <> ".." Then
If (GetAttr(Key(i) & MyFolderName) And vbDirectory) = vbDirectory Then
AllFolders.Add (Key(i) & MyFolderName & "\"), ""
End If
End If
MyFolderName = Dir
Loop
i = i + 1
Loop
For Each Key In AllFolders.keys
MyFileName = Dir(Key & "*.doc*")
Do While MyFileName <> ""
AllFiles.Add (Key & MyFileName), ""
MyFileName = Dir
Loop
Next
lastrow = Sheet2.Range("a" & Rows.Count).End(xlUp).Row + 1
Sheet2.Cells(lastrow, 1).Resize(UBound(AllFiles.keys) + 1) = WorksheetFunction.Transpose(AllFiles.keys)
Set AllFolders = Nothing
Set AllFiles = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
End Sub