Determine if a workbook is already open using VBA in Microsoft Excel

by  About
       

The function below can be used to determine if a workbook is open or not:

Function WorkbookOpen(WorkBookName As String) As Boolean
' returns TRUE if the workbook is open
    WorkbookOpen = False
    On Error GoTo WorkBookNotOpen
    If Len(Application.WorkBooks(WorkBookName).Name) > 0 Then
        WorkbookOpen = True
        Exit Function
    End If
WorkBookNotOpen:
End Function

Example:

If Not WorkbookOpen("MyWorkbookName.xls") Then 
    Workbooks.Open "MyWorkbookName.xls"
End If


Leave a Reply

Your email address will not be published. Required fields are marked *


five + 9 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>