I have a file name saved by date, and I'd like to make a conditional formula to check to see if there's a file name with the current date in it, and if not, open the previous day's file. This code will open the two files.
How do I use an If Then statement to try to open today's file, and if it doesn't exist, then open yesterday's file? To complicate things further, it would also be nice to skip weekends, so on Monday, to open Friday's file.
Code:
Sub OpenFile()
Dim strYesterdayFile As String
Dim strTodayFile As String
strFileName = "File " & Format(DateAdd("d", -1, Date), "mm.dd.yy") & ".xls"
strTodayFile = "File " & Format(Now(), "mm.dd.yy") & ".xls"
Workbooks.Open Filename:=strYesterdayFile
Workbooks.Open Filename:=strTodayFile
Sub End
How do I use an If Then statement to try to open today's file, and if it doesn't exist, then open yesterday's file? To complicate things further, it would also be nice to skip weekends, so on Monday, to open Friday's file.