Determining If a Workbook is Referenced by Another Workbook

Written by Allen Wyatt (last updated March 18, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


Marius has a workbook that may be referenced (linked to) by other workbooks. He would like to delete this workbook, but cannot if it is linked to others. The problem is that he doesn't know how to figure out if this workbook is referenced by other workbooks or not.

Excel keeps track of outbound links for a workbook (just choose Edit Links from the Data tab of the ribbon to see what links there are within the current workbook), but for most versions of the program does not keep track of inbound links. The only versions that do allow you to track inbound links are some enterprise versions of Excel, as described at this Microsoft site:

For the rest of us non-enterprise users, we are left to our own devices. This means that in order to see if there is a link targeting the current workbook, you actually need to open every other workbook on your system and check its links to see if any of them reference the current workbook.

This process is tedious at best but could best be classified as daunting. This makes it a perfect candidate for a macro. After all, a macro could open a bunch of other workbooks and check for a link to a specific workbook. Here's a simple macro that can check all the workbooks in a specific folder:

Sub FindWbkReferences()
    Dim folderp As String
    Dim fname As String
    Dim sMsg As String
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim cel As Range

    folderp = "C:\Documents\Excel\"
    fname = Dir(folderp & "*.xlsx")
    sMsg = ""

    Do While fname <> ""
        Set wb = Workbooks.Open(folderp & fname) 'Open workbook
        For Each ws In wb.Worksheets    'Check each worksheet
            ' Loop through all cells in the worksheet
            For Each cel In ws.UsedRange.Cells
                ' Check if the cell contains a formula referencing
                ' the specified file
                If InStr(cel.Formula, "WbkToDelete") > 0 Then
                    'Save location of reference
                    sMsg = sMsg & "Workbook: " & "'" & wb.Name & "'"
                    sMsg = sMsg & " contains reference to this workbook in "
                    sMsg = sMsg & " worksheet: " & ws.Name & ", "
                    sMsg = sMsg & " cell: " & cel.Address & vbCr
                End If
            Next cel
        Next ws
        fname = Dir()
    If sMsg = "" Then sMsg = "No inbound references located"
    MsgBox sMsg
End Sub

The macro checks every formula in every used cell of every worksheet of every workbook in a given folder. The folder to check is specified in the folderp variable, and you'll note that it also specifies workbooks of a certain type. (In this case, it is XLSX workbooks.)

This process can take some time to accomplish, depending on how many folders there are. Plus, it becomes quickly apparent that this isn't a very robust approach. The problem is that you may need to check workbooks in multiple folders, or there could be links from objects other than formulas or even from macros. Or, there could be inbound links from other programs in the Office suite, such as Word or PowerPoint.

Could you adjust your macro to check for every possible source of an inbound link? Conceivably you could, but it would quickly become a task almost as arduous as opening and checking each potential source manually.

You could, if you desire, try a semi-manual way to look for inbound links. Let's say that you want to check for links to MyBook.xlsx. Close Excel and then open a Windows Explorer window. In the Search box (upper-right corner), enter the workbook name (MyBook.xlsx) and let Windows do its searching. Since Windows searches within each file for your text, you should soon see a list of any files that contain "MyBook.xlsx".

Perhaps the best approach, however, is to simply rename the workbook you are thinking of deleting. This would break any inbound links because the target of the link is no longer existent—you've renamed it. You can then continue to use your system as normal over the next few weeks or few months. If you get no notifications of broken links, then you can safely delete the workbook. A variation on this is to move the workbook instead of renaming it. Simply move it to an external device, such as a flash drive, and then go about your work. If you discover down the road you still need it, then you can always move it back, as needs dictate.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7639) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

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. ...


Weekdays in a Month

Want to find out how many of a particular weekday occur within a given month? Here's how you can find the desired ...

Discover More

Printing Unwanted Blank Envelopes

When you try to print an envelope in Word, it can be vexing if the envelope always goes through the printer and remains ...

Discover More

Using the WEEKNUM Function

Need to know which week of the year a particular date falls within? Excel provides the WEEKNUM function so you can easily ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Strange Message about Others Making Changes in a Workbook

Have you ever tried to save a workbook, only to be notified that someone else has made changes in it? What if you are the ...

Discover More

Creating a Workbook Clone

If you are afraid of messing up a workbook, consider doing your work on a clone of the workbook. Excel provides an easy ...

Discover More

Printing Workbook Properties

Want to create a printed record of the properties associated with a workbook? There is no easy way to do it in Excel. ...

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?

2023-07-02 10:30:08

J. Woolley

For more on this subject, see

2023-03-26 15:31:03

J. Woolley

My Excel Toolbox now includes the LinksToMe macro to identify all workbooks with an external data link referencing the active workbook.

2023-03-18 11:37:56

J. Woolley

The Tip's macro "checks every formula in every used cell of every worksheet of every workbook in a given folder." To make it more efficient, replace the following statements
    For Each cel In ws.UsedRange.Cells
    Next cel
with these statements
    On Error Resume Next
    For Each cel In ws.UsedRange.SpecialCells(xlCellTypeFormulas)
    Next cel
    On Error GoTo 0
But to find all workbooks that reference MyBook.xlsx, you don't need to look at formulas for each cell of every worksheet of every workbook. You can look for workbooks that have an external link to MyBook.xlsx instead. Here is a modified version of the Tip's macro that should run faster:

Sub FindWbkReferences()
    Const WorkbookToDelete = "MyBook.xlsx"
    Const FolderPath = "C:\Documents\Excel\"
    Dim fname As String, msg As String, wb As Workbook
    Dim oldAS As Variant, oldCM As Variant, V As Variant, item As Variant
    oldCM = Application.Calculation
    Application.Calculation = xlCalculationManual
    oldAS = Application.AutomationSecurity
    Application.AutomationSecurity = msoAutomationSecurityForceDisable
    Application.ScreenUpdating = False
    fname = Dir(FolderPath & "*.xls?")
    On Error Resume Next
    Do While fname <> ""
        Set wb = Workbooks.Open(FolderPath & fname, _
            UpdateLinks:=0, Password:="")
        If Err Then
            msg = msg & vbNewLine & "could not open " & fname
            V = wb.LinkSources(xlExcelLinks)
            If Not IsEmpty(V) Then
                For Each item In V
                    If InStr(item, WorkbookToDelete) > 0 Then
                        msg = msg & vbNewLine & wb.Name
                        Exit For
                    End If
                Next item
            End If
            wb.Close SaveChanges:=False
        End If
        fname = Dir()
    On Error GoTo 0
    Application.ScreenUpdating = True
    Application.AutomationSecurity = oldAS
    Application.Calculation = oldCM
    If msg = "" Then
        msg = "no files referencing " & WorkbookToDelete
        msg = "files referencing " & WorkbookToDelete & msg
    End If
    MsgBox FolderPath & vbNewLine & msg
End Sub

Replace Const WorkbookToDelete and Const FolderPath with appropriate values. Notice this version checks *.xlsm and *.xlsb as well as *.xlsx workbooks.
In each workbook that references MyBook.xlsx as an external link, you can use My Excel Toolbox's ListExLinks dynamic array function as follows:
The result is similar to the Data > Queries & Connections > Edit Links dialog minus its Update column, but ListExLinks optionally adds a Reference column to identify cells that contain a formula referencing the link.
When using pre-2021 versions of Excel without support for dynamic arrays, consider UseSpillArray.pdf.

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.