Excel Guides

Checking if a Workbook is Already Open in Excel

If you're working in Microsoft Excel, it's important to know whether or not a workbook is already open. There are a few different ways to check this:

  1. The Application.Workbooks property returns a Workbooks collection that represents all the open workbooks in Excel. You can loop through this collection and check the Name property of each Workbook object to see if the workbook you're looking for is already open:
For Each WB In Application.Workbooks
    If WB.Name = "MyWorkbook.xlsx" Then
        ' Workbook is already open
    End If
Next WB
  1. Another way to check if a workbook is already open is to use the Application.FileSearch method. This method searches for files and folders in a specified directory and returns a FileSearch object that represents the results of the search.

  2. You can then loop through the FoundFiles property of the FileSearch object and check the Name, Path, and Extension properties of each file to see if it matches the workbook you're looking for:

Dim fso As New FileSearch
Dim strFile As String
fso.SearchPath = "C:\Documents\" & _ 
                  "and Settings\username\My Documents" 
fso.FileName = "MyWorkbook.*" 

 For Each strFile In fso.FoundFiles 

     If Dir(strFile) <> "" Then 

         ' Workbook is already open 

     End If 

 Next strFile 

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.