Interesting. It stops on my system. We can add a "stop" command I suppose. Once more...:
Sub OpenByDate()
'Opens a sheet based on date search
Dim TheString As String, TheDate As Date, ThePath As String
Dim TheBook As Workbook
TheDate = Date
ThePath = "C:\holdings\" & WorksheetFunction.Text(TheDate, "YYYY¢MM¢DD") & "\"
ThePath = WorksheetFunction.Substitute(ThePath, "¢", "_")
TheString = "portfolio " & WorksheetFunction.Text(TheDate, "MM.DD.YYYY") & ".xls"
On Error Resume Next
Do
Workbooks.Open ThePath & TheString
Set TheBook = Workbooks(TheString)
If TheBook Is Nothing Then 'Not open
TheDate = TheDate - 1
ThePath = "C:\holdings\" & WorksheetFunction.Text(TheDate, "YYYY¢MM¢DD") & "\"
ThePath = WorksheetFunction.Substitute(ThePath, "¢", "_")
TheString = "portfolio " & WorksheetFunction.Text(TheDate, "MM.DD.YYYY") & ".xls"
Else 'It opened
Set TheBook = Nothing
Exit Sub
End If
Loop
MsgBox "You should never see this message"
End Sub
Bookmarks