I have within a folder a report worksheet and a macro worksheet that create reports on a daily based. Therefore this folder has tons of reports and I need to add some code to the macro worksheet to delete reports worksheets that are older that 90 days. This is the code that I believe could do the job; Do you have any suggestions or maybe a different approach?
Dim Filename As String, RecentFile As String, RecentDate As Date
Dim DelFile As String, Directory As String, myDir As String, OldFile As String
Sub Delete90DaysOldFiles()
myDir = "c:\data\excel\reports"
If Right(myDir, 1) <> "\" Then Directory = myDir & "\"
Filename = Dir(Directory & "" & "*.xls", 0)
Do While Filename <> ""
RecentFile = Filename
RecentDate = FileDateTime(Directory & Filename)
If FileDateTime(Directory & Filename) < Date - 90 Then '90 days old
OldFile = Filename
End If
Filename = Dir
If OldFile <> "" Then
Kill OldFile
End If
Loop
End Sub
Bookmarks