Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Checking if a Workbook is Already Open.

Checking if a Workbook is Already Open

Written by Allen Wyatt (last updated July 26, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Macros are often used to slice, dice, and otherwise process information contained in workbooks. This presumes, of course, that the workbook that contains the information is actually open. If it is not, then your macro will obviously need to include code to actually open the needed workbook.

Opening a workbook can really slow down a macro; it takes time to access the disk and load the file. Thus, if your macro can check to see if a workbook is open before going through the hassle of actually trying to open it, you could speed up your macros greatly if the workbook is found to already be open.

One very flexible way to approach the task of checking whether a workbook is open is to use a function that does the checking, and then simply returns a TRUE or FALSE value based on whether the workbook is open. The following short macro performs this succinct task:

Function AlreadyOpen(sFname As String) As Boolean
    Dim wkb As Workbook
    On Error Resume Next
    Set wkb = Workbooks(sFname)
    AlreadyOpen = Not wkb Is Nothing
    Set wkb = Nothing
End Function

To use the function, just pass it the name of the workbook you want to check, in the following manner:

    sFilename = "MyFileName.xls"
    sPath = "C:\MyFolder\MySubFolder\"
    If AlreadyOpen(sFilename) Then
        'Do not have to open
        Workbooks.Open sPath & sFilename
    End If


If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10985) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Checking if a Workbook is Already Open.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Chapter Numbers in Indexes and TOAs

Word allows you to define prefixes for page numbers. These are often used for chapter or section numbers in a large ...

Discover More

Copying a File in VBA

Need to have your macro copy a file from one place to another? It's easy to do using the FileCopy command, described in ...

Discover More

Lost Data in Word

Use Word long enough and you eventually will lose some of your work. (And, it seems to be a rule that this will occur ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Pausing Macros for User Input

Does your macro need to get some input from a user? Here are the ways that Excel provides for that input to be solicited.

Discover More

Saving Information in a Text File

The VBA programming language provided with Excel allows you to create and modify text files quite easily. Here's how to ...

Discover More

Dissecting a String

VBA is a versatile programming language. It is especially good at working with string data. Here are the different VBA ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 + 7?

2019-01-13 09:44:50

Simon Freeman

Alans - many thanks. - Simon

2019-01-07 12:44:42

Alan F. Bouvier

Our system has shared networks mapped to drive letters. I have seen the file paths show up with either the drive letter or the full server path.
Since Excel includes the path as part of the file name, sometimes is doesn't recognize that a file is open.
I usually just strip off the path and compare the file name; however, a more accurate method would be to force the paths to be canonical and then compare.
This then leaves you open to the possible error of "Excel can't open two files with the same name."

2019-01-07 05:10:46

Alan Elston

Set wkb = Workbooks(sFname) will not work if workbook sFname is closed because
is a "collection" object of all open workbooks. So workbook sFname will not be found in that collection object, so that code line will error. ( Our running routine will not error as On Error Resume Next tells VBA to ignor an error and just keep going after the line that errored )

2019-01-07 05:05:59

Alan Elston

@ Simon Freeman
Re AlreadyOpen = Not wkb Is Nothing

VBA will usually read things from approximately right to left , ( unless you put things in brackets, as in normal maths, to ensure that some things are done in a specific order )
So this is what VBA does in the following order

wkb Is Nothing
This will return True if wkb is Nothing and False if wkb is something.
(wkb will be something if this bit did not error: Set wkb = Workbooks(sFname). That is to say wkb will be something if the workbook named sFname is open, because then Set wkb = Workbooks(sFname) will have worked to fill the variable wkb. If that command had not worked, then wkb will be at its initial default state of Nothing

Not wkb Is Nothing
This Not simply puts a False to True and a True to a False

So example.
Say your Workbook, sFname is closed.
Set wkb = Workbooks(sFname) will not work so wkb stays at its default initial state of Nothing
wkb Is Nothing will give True, because it is true that wkb Is Nothing
Not wkb Is Nothing will change that True to False
So then AlreadyOpen = Not wkb Is Nothing
…. , AlreadyOpen = False …….which is the result you want

Alan Elston

2019-01-06 05:38:40

Simon Freeman

Alan - could you explain this line from the first Macro: AlreadyOpen = Not wkb Is Nothing - Thanks - Simon

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.