ブックが開かれているか確認

Sub Sample()
    Dim fName As String
    fName = "test.xlsx"
    If IsOpenBook(fName) Then
        '処理
    End If
End Sub
Function IsOpenBook(ByVal bookName As String) As Boolean
    Dim res As Boolean
    Dim wb As Workbook
     
    For Each wb In Workbooks
        If wb.Name = bookName Then
            res = True
            Exit For
        End If
    Next
     
    IsOpenBook = res
End Function