How to Quickly Check if a Workbook is Open or Closed in Excel

Checking if a workbook is open or closed in Excel can be achieved using Visual Basic for Applications (VBA) code. Here's how to set it up:

Step 1: Open VBA Editor

Press Alt + F11 to open the VBA Editor.

Step 2: Insert a New Module

In the Project Explorer, right-click on any of the items and choose Insert > Module. This will create a new module.

Step 3: Enter the VBA Code

In the new module, paste the following VBA code:

Function IsWorkbookOpen(WorkbookName As String) As Boolean
    Dim tempWorkbook As Workbook
    On Error Resume Next
    Set tempWorkbook = Application.Workbooks(WorkbookName)
    If Not tempWorkbook Is Nothing Then IsWorkbookOpen = True
    On Error GoTo 0
End Function

Step 4: Use the Function in Excel

Now, you can use this function in Excel like any other function. For instance, =IsWorkbookOpen("Book1") will return TRUE if "Book1" is open and FALSE if it's not.

Previous
Previous

How to Quickly Insert a Line Based on the Current Date in Excel

Next
Next

How to List All Dates Between Two Dates in Excel