December 10, 2008 at 00:04
· Filed under VBA, VBA Examples
Selva V Pasupathy, HSBC Global Resourcing, Hyderabad
|
Option Explicit ‘___________________________________________________________________________ ‘*************************************************************************** ‘* MODULE NAME: CODE TO COMPARE IF ANY FILENAME IS > 90 DAYS OLD ‘* AUTHOR: Selva V Pasupathy, HSBC Global Resourcing, Hyderabad ‘* ‘* ‘* CONTACT: socko@rediffmail.com ‘* WEB SITE: http://socko.wordpress.com ‘* NOTES: ‘* ———————————————————————— ‘* ———————————————————————— ‘* ‘*___________________________________________________________________________ ‘***************************************************************************
‘ CODE TO COMPARE IF ANY FILENAME IS > 90 DAYS OLD
Const Files_Location = “J:\Falcon\Management\INFILL REPORTS\FCD\”
Sub Delete_Files(ByRef sDir As String) Dim i As Integer Dim dt2Delete, strDT As Date With Application.FileSearch .LookIn = sDir .SearchSubFolders = False .FileType = msoFileTypeExcelWorkbooks .Execute End With With Application.FileSearch If .Execute() > 0 Then MsgBox “There were ” & .FoundFiles.Count & _ ” file(s) found.” For i = 1 To .FoundFiles.Count MsgBox .FoundFiles(i) strDT = Mid(.FoundFiles(i), _ InStrRev(.FoundFiles(i), ” “, _ -1, vbTextCompare) + 1, 255) dt2Delete = Format(Now() – 90, “ddmmyyyy”) MsgBox dt2Delete If strDT < dt2Delete Then MsgBox strDT MsgBox “NEED TO DELETE” Else MsgBox “NEED NOT DELETE” End If Next i Else MsgBox “There were no files found.” End If End With
End Sub
Sub testDeleteFiles() Call Delete_Files(Files_Location) End Sub
|
Permalink