Você está na página 1de 7

Spreadsheet skills: locating links

June 2011

This month, Spreadsheet Skills revisits one of its early topics looking again at those pesky external links and considering how to list them in an Excel worksheet. By Liam Bastick, director with Corality. Query Is it possible to list all of the formula links in a model? I want to check that they are working correctly and that there are no accidental linkages to other Excel files. Advice Regular readers may notice this is a similar question to the February 2009 article discussing how to identify phantom links. This piece discussed finding all types of external links not just formula links but only to identify them. To recap: Formula links When a file contains formula links, it is relatively straightforward to hunt them out:

close all workbooks except the active workbook with the links in in Excel 2003 / earlier, on the Edit menu, click Find; in Excel 2007 and later versions, click on Find & Select of the Editing section of the Home tab or simply use Ctrl + F in all versions.

Location of Find & Select in Excel 2007


click Options in the Find what box, enter [ (with no inverted commas). These square brackets will always appear in formula links in the Within box, click Workbook in the Look In box, click Formulas click Find All in the box at the bottom, look in the Formula column for formulas that contain [ to select the cell with a link, select the row in the box at the bottom.

Find dialog box (illustration) The problem here is that our reader wants the list in the bottom box, ie 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. Checking Excels security settings Because macros may execute all sorts of nasty code, Excels default setting is that macros will not run automatically. To ensure the macro below will work, you will first need to check / amend Excels security settings: Excel 2003 and earlier

call up the Options dialog box (Tools -> Options or ALT + T + O) select the Security tab in the Macro security section, click on the Macro Security button

ideally, select / confirm the setting as Medium. This means you can choose whether or not to run macros Excel may have to be closed and reopened for these changes to be adopted.

Excel 2007

click on the Office button click on Excel Options (ALT + T + O is the equivalent of these first two steps) select Trust Center from the left hand columnar list in the Microsoft Office Excel Trust Center section, click on the Trust Center Settings button select Macro Settings from the left hand columnar list (if the Developer tab is displayed on the ribbon, ALT + L + AS will get you to this point immediately) in the Macro Settings section, select Enable all macros (note this is a slightly more dangerous option than its Excel 2003 counterpart).

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 (see next page).

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, open this Notepad document (8KB) and paste in the code it contains, exactly as it is written. To run this code, exit the Visual Basic Editor (simply close the main window) and then: Excel 2003 and earlier

go to Tools -> Macro -> Macros (ALT + F8).

Excel 2007 Ensure the Developer tab on the ribbon is visible as follows:

click on the Office button click on Excel Options (ALT + T + O is the equivalent of these first two steps)

select Popular from the left hand columnar list in the Top options for working with Excel section, check that the third check box Show Developer tab in the Ribbon is ticked click OK go to the Developer tab in the ribbon in the Code group, click on Macros

Alternatively, ignore simply use the keyboard shortcut ALT + F8. This will then bring up the following dialog box:

Select the macro Select the ThisWorkbook.ListExternalLinks macro (it may appear simply as ListExternalLinks) and click on the Run button. This will execute the macro and display all external formula links. Beware ... 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. You may have noticed Astute readers will have noticed that I havent really explained the above macro, although for those of you so inclined, hopefully it does make sense. While this months article does answer our readers question, it is intended more as an introduction to getting set up for coding macros, highlighting the Visual Basic Editor and illustrating the classic error in Excel 2007. My number one macro tip? Keep them simple and minimal. If you have a query for the spreadsheet skills section, please feel free to drop Liam a line at liam.bastick@corality.com, or visit the Corality website. Links February 2009s spreadsheet skills Spreadsheet skills for forecasting, planning, budgeting mastercourse CIMA professional development CIMA on demand