Created On:  26 August 2011
 
It is possible to verify whether a specific Excel Workbook is open using TestPartner. The code below shows a function that returns TRUE if the Excel Workbook is open and FALSE if it is not open or a different Workbook is open.

Option Explicit
 
 '----------------------------------------------------------
 'Must set a reference (Tools | References) to
 'Microsoft Excel 11.0 (or relevent version) Object Library
 '--------------------
 ' Version:
 '  12.0 = 2007
 '  11.0 = 2003
 '  10.0 = 2002 or XP
 '   9.0 = 2000
 '   8.0 = 1997
 '--------------------
 'This will make use of 'Early Binding' and give us access
 'to the Excel Object Model and it's intellisense.
 '----------------------------------------------------------

 
Function IsXLBookOpen(strName As String) As Boolean
    
     'Function designed to test if a specific Excel
     'workbook is open or not.

    
    Dim i As Long, XLAppFx As Excel.Application, NotOpen As Boolean
    
     'Find/create an Excel instance
    On Error Resume Next
    Set XLAppFx = GetObject(, "Excel.Application")
    If Err.Number = 429 Then
        NotOpen = True
        Set XLAppFx = CreateObject("Excel.Application")
        Err.Clear
    End If
    
     'Loop through all open workbooks in such instance
    For i = XLAppFx.Workbooks.Count To 1 Step -1
        If XLAppFx.Workbooks(i).Name = strName Then Exit For
    Next i
    
     'Set all to False
    IsXLBookOpen = False
    
     'Perform check to see if name was found
    If i <> 0 Then IsXLBookOpen = True
    
     'Close if was closed
    If NotOpen Then XLAppFx.Quit
    
     'Release the instance
    Set XLAppFx = Nothing
    
End Function


Sub Main()
    MsgBox IsXLBookOpen("Personal.xls")
End Sub


This code verifies if an Excel Workbook called "Personal.xls" is currently open.

Note that you need to add the reference for the relevant Excel Object Library in order for this code to compile correctly.
Incident #2533367