The below code is supposed to check if there is "Book1.xlsx" workbook currently open. If it's not then it is supposed to open it.
When it checks for the open workbook and cannot find it, the program should throw a "subscript out of range" error. To handle this I added "On error resume next" however it still pops up on the screen.
Do you know why this is not handled by the error trapping routine (the error should have been ignored and the code execution continued)?
Sub TestBook()
Dim strBookName As String, filepath As String, TestBook As Workbook, usr As String
usr = Environ("username")
filepath = "C:\Users\" & usr & "\Desktop\book1.xlsx"
strBookName = "book1.xlsx"
On Error Resume Next
Set TestBook = Workbooks(strBookName)
On Error GoTo 0
If TestBook Is Nothing Then
Set TestBook = Workbooks.Open(FileName:=filepath)
Else
MsgBox strBookName & " is open", vbOKOnly + vbInformation
End If
End Sub