I'm searching for certain files on a specified, referenced drive in Worksheet("Parameters"). These files have to be last modified before a certain date and the search should not locate certain files in specified, referenced folders. The goal of this project is to collect "stale files," and, after I have collected them, move them, and delete them. I am not at the moving or deleting stages just yet. Please help with the following code:
Sub ListFiles()
On Error Resume Next
Sheets.Add
Call CreateList
Call MsgBeSure
End Sub
Sub CreateList()
Dim filePath As Variant, fsObject As Variant, file As Variant
Dim i As Long, Lastrow As Long
Dim Count As Integer
Lastrow = Worksheets("Parameters").Range("F65536").End(xlUp).Row
Set PFcell = Worksheets("Parameters").Cells(Count, 6)
With Application.FileSearch
.LookIn = Range("Drive")
.SearchSubFolders = Range("Include_Subfolders")
.Filename = "*.*"
.Execute
For Each filePath In .FoundFiles
i = 1 + i
Set fsObject = CreateObject("Scripting.FileSystemObject")
Set file = fsObject.GetFile(filePath)
ActiveSheet.Cells(i, 1) = file.Drive
ActiveSheet.Cells(i, 2) = file.Name
ActiveSheet.Cells(i, 3) = file.ParentFolder
For Count = 19 To Lastrow
If ActiveSheet.Cells(i, 3) = PFcell.Value Then
Exit Sub
End If
Next Count
ActiveSheet.Cells(i, 4) = file.Path
ActiveSheet.Cells(i, 5) = file.DateLastModified
If ActiveSheet.Cells(i, 5) = Worksheets("Parameters").Range("Before_Date").Value Then
Exit Sub
End If
Next filePath
.NewSearch
End With
End Sub
Sub MsgBeSure()
MsgBox "Do NOT move or delete gathered, stale data before consulting with your coworkers and supervisors and receiving their input. Be sure to sort and assess the gathered, stale data for file sequences or data that should not be deleted."
End Sub
... If I take out the:
For Count = 19 To Lastrow
If ActiveSheet.Cells(i, 3) = PFcell.Value Then
Exit Sub
End If
Next Count
and the...
If ActiveSheet.Cells(i, 5) = Worksheets("Parameters").Range("Before_Date").Value Then
Exit Sub
End If
... the macro works great. However, those are the most important features that I need. Since I'm searching through more than 100,000 using excel 2003, I cannot list all files within the given parameters. It has to be only the certain files that fall within the specified, referenced criteria.
Your help is appreciated!
Sub ListFiles()
On Error Resume Next
Sheets.Add
Call CreateList
Call MsgBeSure
End Sub
Sub CreateList()
Dim filePath As Variant, fsObject As Variant, file As Variant
Dim i As Long, Lastrow As Long
Dim Count As Integer
Lastrow = Worksheets("Parameters").Range("F65536").End(xlUp).Row
Set PFcell = Worksheets("Parameters").Cells(Count, 6)
With Application.FileSearch
.LookIn = Range("Drive")
.SearchSubFolders = Range("Include_Subfolders")
.Filename = "*.*"
.Execute
For Each filePath In .FoundFiles
i = 1 + i
Set fsObject = CreateObject("Scripting.FileSystemObject")
Set file = fsObject.GetFile(filePath)
ActiveSheet.Cells(i, 1) = file.Drive
ActiveSheet.Cells(i, 2) = file.Name
ActiveSheet.Cells(i, 3) = file.ParentFolder
For Count = 19 To Lastrow
If ActiveSheet.Cells(i, 3) = PFcell.Value Then
Exit Sub
End If
Next Count
ActiveSheet.Cells(i, 4) = file.Path
ActiveSheet.Cells(i, 5) = file.DateLastModified
If ActiveSheet.Cells(i, 5) = Worksheets("Parameters").Range("Before_Date").Value Then
Exit Sub
End If
Next filePath
.NewSearch
End With
End Sub
Sub MsgBeSure()
MsgBox "Do NOT move or delete gathered, stale data before consulting with your coworkers and supervisors and receiving their input. Be sure to sort and assess the gathered, stale data for file sequences or data that should not be deleted."
End Sub
... If I take out the:
For Count = 19 To Lastrow
If ActiveSheet.Cells(i, 3) = PFcell.Value Then
Exit Sub
End If
Next Count
and the...
If ActiveSheet.Cells(i, 5) = Worksheets("Parameters").Range("Before_Date").Value Then
Exit Sub
End If
... the macro works great. However, those are the most important features that I need. Since I'm searching through more than 100,000 using excel 2003, I cannot list all files within the given parameters. It has to be only the certain files that fall within the specified, referenced criteria.
Your help is appreciated!