This article revisits one of the early topics – those pesky external links, this time considering how to list them in an Excel worksheet. By Liam Bastick, Director with SumProduct Pty Ltd.
Is it possible to list all of the formula links in a model? I want to check they are working correctly and that there are no ‘accidental’ linkages to other Excel files.
Regular readers may notice this is a similar question to the article discussing how to identify ‘phantom’ links. This article discussed finding all manner of external links – not just formula links – but only considered how to identify them.
To recap:
When a file contains formula links, it is relatively straightforward to hunt them out:
Location of Find & Select in Excel 2007

Find Dialog Box (Illustration)

The problem here is that our reader wants the list in the bottom box, i.e. the 251 links displayed at the bottom of the above illustration. This requires writing VBA code. Before this though, we need to make sure that the code will run.
Because macros may execute all sorts of nasty code, Excel’s default setting is set so that macros will not run automatically. To ensure the macro below will work, you will first need to check / amend Excel’s security settings, viz.
| Excel 2003 and earlier | Excel 2007 and later |
|
|
I am not a great fan of macros. I believe them to be ‘black box’ items and dangerous in the wrong hands. They should only be used as a last resort. However, this is one such instance.
Adding a macro that is already scripted (see below) requires access to the Visual Basic Editor (ALT + F11). Typically, this will be displayed as follows:
Visual Basic Editor

Not all four windows may be displayed and the grey section may appear white. The important thing is to ensure the Project Explorer Window (below) is visible:
Typical Project Explorer Window

If it is not visible, simply invoke the keyboard shortcut CTRL + R (or else go to View -> Project Explorer).
Depending upon the files open and add-ins available in Excel, the contents may differ significantly from the illustration above. The key point is to locate the file with the external links (in our example, the imaginatively titled ‘Book 1’) in VBAProject and expand the selection in order to double-click on ‘ThisWorkbook’:
Where to Paste the Code

The graphic above shows where to paste the code, i.e. into the Code window (top right hand window).
Next, paste in the following code (using the attached Notepad file):
Macro

To run this code, exit the Visual Basic Editor (simply close the main window) and then:
| Excel 2003 and earlier | Excel 2007 and later |
|
|
This will then bring up the following dialog box:
Run Code

Select the macro ‘ThisWorkbook.ListExternalLinks’ macro and click on the ‘Run’ button. This will execute the macro and display all external formula links.
For readers using Excel 2007 and subsequent versions, be careful when saving this file. It is safest to use the ‘Save As…’ option:
Save As Dialog Box

The default ‘Save as type:’ setting for Excel 2007 onwards is ‘Excel Workbook’, but this is a macro-disabled (and moreover, removed) setting. To retain the macro in the saved file, ensure that either the ‘Excel Macro-Enabled Workbook’ or, for better compatibility with earlier incarnations of Excel, ‘Excel 97-2003 Workbook’ type is selected.