Sorry, I'm new...Is this how you tag codes?
Do you do separate loops for the path and the string, like this? or is this wrong...
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