So I have a VBA code to open a workbook saved with yesterday's date. It looks like the following:
Sub OpenYesterday
Dim OpenPath As String
OpenPath = "N:\File\": & "today_" (Now(),-1, "YYYYMMDD") & ".xlsx"
Workbooks.Open Filename:=OpenPath
EndSub
Obviously I have my full filepath in the code but how can I loop this so it will open the last workbook that has been saved? For example, on Monday I would want it to pull Friday's report. I save a workbook every weekday with that days date. Example: Today is 1/13/2014 and I want this code to open the workbook that was saved on Friday 1/10/2014. I have tried the "WorkDay" function which works as well but lets say I didn't save a workbook today (1/13/2014) so tomorrow the last workbook would still be Friday's 1/10/2014 workbook. Is there a way to loop this code so that it will continually look for yesterday's workbook and if there is not a workbook from yesterday it would loop back two days until the 1/11/2014 workbook, then if that isn't saved it would loop back to the 1/10/2014 workbook? So tomorrow if there is no workbook saved with today's 1/13/2014 workbook it would loop 3 times to find the workbook saved on 1/10/2014?
Sorry if this is confusing, let me know if you need further explanation.
Thank you.
Im thinking I will just need it to loop back to "Now(), -2" if there is no workbook from yesterday, and "Now(), -3" if there is no report from 2 days ago, etc...
Bookmarks