Sorry...hope this is right.
Anyway, I am not sure if you have do this loop for the path and the string or once for both...if someone could take a look at this and let me know what I am doing wrong I would really appreciate it. Thanks.
Option Explicit
Sub OpenByDate()
'Opens a sheet based on date search
Dim TheString As String, TheDate As Date, ThePath As String
ThePath = "c:\holdings\" & WorksheetFunction.Text(TheDate, "YYYY_MM_DD") & "\"
TheDate = Date
TheString = "test " & WorksheetFunction.Text(TheDate, "MM.DD.YYYY") & ".xls"
Do
On Error Resume Next
Workbooks.Open ThePath
If Err <> 0 Then
TheDate = TheDate - 1
ThePath = "c:\holdings\" & WorksheetFunction.Text(TheDate, "YYYY_MM_DD") & "\"
Do
On Error Resume Next
Workbooks.Open TheString
If Err <> 0 Then
TheDate = TheDate - 1
TheString = "test " & WorksheetFunction.Text(TheDate, "MM.DD.YYYY") & ".xls"
End If
Loop Until Err = 0
End Sub
Bookmarks