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


Periodically Delete TMP Files

After using Word for a while, you may notice some "litter" of unused files on your hard drive. This tip explains how ...

Discover More

Status Bar Summing No Longer Available

When you select a range of cells, Excel normally displays the sum of those selected cells on the status bar. If the sum ...

Discover More

Using the INT Worksheet Function

The INT function allows you to convert a value to an integer. The effect the function has depends on the characteristics ...

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)

Closing a Read-Only Workbook

When you create a workbook that is read-only, users can still make changes to the workbook. When they exit, they are ...

Discover More

Viewing Workbook Statistics

Excel keeps track of a range of stats about each workbook you use. If you want to take a look at those stats, it's easy; ...

Discover More

Shrinking Workbook Size

As you work with a workbook over time, it is possible for the workbook to grow to a huge size. If you want to shrink the ...

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 8 - 4?

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.