My boss likes it so much that he wants me to use it as a tool to see if people are submitting their reports on time. (There's only about 150 of these). The problem is, these reports have date stamps and the name changes each time the report is issued. It's not so much of an issue with most of the daily reports as thier date stamps are predictable and I can generate a file name from a root name based on the current day.
However, the weekly and monthly reports can be issued on any number of days. For example, the "foo report" is due within the first 5 days of the month, so it could be foo080301.xls, foo080302.xls ,... foo080305.xls. All I know is that the format will be YYMMDD. There are differences in the format of date stamps for different reports. Some even stamp down to the second of generation.
Is there a way I can specify the file name in such a way to accept a wildcard. For example "foo??????.xls" I know that there will be an issue if there are more than one file that matches the pattern; for example foo080201 and foo080303. I am willing to live with finding the last (preferably) or first (if I have to) of these files. I wil handle the ambiguity procedurally. (I.e. you have to put the report in the folder of the month.). Also I could get smart enough to use month and year to build the string so it looks like foo0803??.xls before feeding it to the function.
So I would like to call the following function with arguments like so: FileDate("foo??????.xls","\\server\path\March")
If it helps, the date stamp is always at the end of the file name before the extention. E.g foo080303.xls or foo080303.pdf or foo080303.csv.
Can do?
CODE
Public Function FileDate(FileName As String, Optional PathName As String) As Date
Application.Volatile
Dim myFSO, myFileObject
Dim datLastModified As Date 'Date and time the file was last modified.
If Len(PathName) = 0 Then
PathName = ThisWorkbook.path
End If
FileName = PathName & "\" & FileName
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set myFileObject = myFSO.GetFile(FileName)
With myFileObject
datLastModified = .dateLastModified
End With
FileDate = datLastModified
End Function
Application.Volatile
Dim myFSO, myFileObject
Dim datLastModified As Date 'Date and time the file was last modified.
If Len(PathName) = 0 Then
PathName = ThisWorkbook.path
End If
FileName = PathName & "\" & FileName
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set myFileObject = myFSO.GetFile(FileName)
With myFileObject
datLastModified = .dateLastModified
End With
FileDate = datLastModified
End Function