Determine if a workbook is already open

 1999-12-20    Workbooks    0    56

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
You can use another macro to determine if a workbook is opened by another user or process.


Leave a comment:

Your comment will only be published after it has been moderated and found spam free.
Your e-mail address will only be used to display your Gravatar.