I am trying to loop through filenames to find a date. I do not have a specific date I'm looking for, just trying to pull a date if one exists in the filename . Problem is that the users don't use the same format everytime so I have everything from 1-1-14 to 01-01-2014 to consider. I wrote a function for this but when the date in the file name is 06-23-2014 I get a return of 6/23/201. Example file names are "F2 A-Shift 06-23-2014 Daily Sustaining Report.xls" and "F1C-Shift 6-25-14 Daily Sustaining Report.xls". Any help on a viable solution would be greatly appreciated.
Function GetDate(strName As String) As Date
Dim intLen As Integer, i As Integer
intLen = Len(strName)
If intLen <= 10 Then Exit Function
For i = 1 To intLen - 10
If IsDate(Mid(strName, i, 10)) = True Then
GetDate = (Mid(strName, i, 10))
Exit Function
End If
Next i
GetDate = "1/1/2001"
End Function