Hey Cytop,
Thanks much for your response. Idea was good to get the count for the folders but really that CMD window is one annoying thing that needs to be closed everytime... :p
I've worked out on my codes and am able to get my answers. I've used recursive method to get it work. But its running a bit slow as its calling the function again and again, plus, considering the amount of search its making in the disk. (I must say, I hate loops!!
)
Following is my updated code.
Sub ListFilesFromFolderAndSubFolders()
'
' http://vbaexpress.com/forum/showthread.php?t=10829&page=2
'
Dim f As Object, fso As Object, flder As Object
Dim extn As String, IsXLFile As Boolean
Dim folder As String
Dim wb As Workbook, ws As Worksheet
Dim TotalFiles As Long, TotalFolders As Long
Dim SinceDate As Date
Set wb = ActiveWorkbook
Set ws = ActiveSheet
Set fso = CreateObject("Scripting.FileSystemObject")
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
If .SelectedItems.Count = 0 Then
'MsgBox "Cancel Selected"
End
End If
folder = .SelectedItems(1) 'vPath
End With
'TotalFiles = 0
'TotalFolders = 0
Set flder = fso.GetFolder(folder)
SinceDate = "8/11/2013 0:00:00"
BoostMacroPerformance True, True
RecursiveSearch flder, ws, SinceDate
BoostMacroPerformance False, True
Set flder = Nothing
Set fso = Nothing
End Sub
Private Sub RecursiveSearch(fld As Object, ws As Worksheet, SinceDate As Date)
Dim fold As Object
Dim fl As Object
Dim extn As String, IsXLFile As Boolean
For Each fold In fld.SubFolders
RecursiveSearch fold, ws, SinceDate
Next
For Each fl In fld.Files
extn = Right(fl.Name, Len(fl.Name) - InStrRev(fl.Name, "."))
Select Case extn
Case "xlsx": IsXLFile = True
Case "xlsb": IsXLFile = True
Case "xlsm": IsXLFile = True
Case "xls": IsXLFile = True
Case Else: IsXLFile = False
End Select
If IsXLFile = True And CDate(fl.DateLastModified) >= CDate(SinceDate) Then
'ws.Range("E" & ws.Range("D" & ws.Rows.Count).End(xlUp).Row) = "Yes"
ws.Range("A" & ws.Rows.Count).End(xlUp).Offset(1, 0) = fl.Path
End If
Next
End Sub
P.S. BoostMacroPerformance is a method that I use to set certain settings of the application (ScreenUpdating, EnableEvents, Calculation and DisplayAlerts) to boost the speed of macro to an extent.
Only thing that am not able to get the property - "Last Saved By" of the file and any alternate ways to boost up the speed by avoiding loop if we can..
Bookmarks