All,
I have the following code below. As you can see that code makes 3 attempts to find my file. I'd like it to just find the file without an error on each attempt. If its in the first attempt, there is no error. If it's in the 2nd or 3rd attempt, then I get errors until it's found. Thank you for any help.
I have the following code below. As you can see that code makes 3 attempts to find my file. I'd like it to just find the file without an error on each attempt. If its in the first attempt, there is no error. If it's in the 2nd or 3rd attempt, then I get errors until it's found. Thank you for any help.
VBA Code:
Sub OpenDOR()
Dim wbMyWorkbook As Workbook
Dim strWBName As String
Dim strWBPathStub As String
Dim strWBPath As String
strWBName = "DO Report " & Format(DateAdd("d", -1, Date), "mm-dd-yy") & ".xlsm" 'yesterday's DO report
strWBPathStub = "https://airport.ishare.tsa.dhs.gov/fieldlocations/MHT/soc/SOC Scheduling/Shared Documents/DOR"
'Attempt 1
strWBPath = strWBPathStub
On Error Resume Next
Set wbMyWorkbook = Workbooks.Open(strWBPath & "\" & strWBName)
If Not wbMyWorkbook Is Nothing Then Exit Sub
'Attempt 2
strWBPath = strWBPathStub & "/" & Format(DateAdd("d", -1, Date), "yyyy.mm")
On Error Resume Next
Set wbMyWorkbook = Workbooks.Open(strWBPath & "\" & strWBName)
If Not wbMyWorkbook Is Nothing Then Exit Sub
'Attempt 3
strWBPath = strWBPathStub & "/Archived/"
On Error Resume Next
Set wbMyWorkbook = Workbooks.Open(strWBPath & "\" & strWBName)
If Not wbMyWorkbook Is Nothing Then Exit Sub
MsgBox "Failed to locate " & strWBName
End Sub