Excel VBA: Refresh Workbook Links (Step-by-Step)
In this article
You can refresh all external workbook links in Excel VBA with a single line: ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources, Type:=xlExcelLinks. This forces Excel to pull the latest values from every linked source file, just as if you had clicked Update Values on the Edit Links dialog. The method works in any macro-enabled workbook (.xlsm) and requires no add-ins. Before you start, make sure the linked source files are saved and stored in the same folders Excel expects; if a source has moved, the refresh will fail until you repair the link.
What You'll Need
- Excel for Windows or Mac with macros enabled. The Visual Basic Editor is included in all desktop editions.
- A workbook that already contains external links (created via Data > Edit Links or by referencing another workbook in a formula).
- The source workbooks saved and accessible on your network or local drive. If they are on a shared drive, confirm you have read access.
- Basic familiarity with opening the VBA editor (Alt+F11 on Windows, or the Developer tab > Visual Basic).
Step-by-Step
- Open the workbook that contains the links. The macro must run from the workbook that holds the external references. If you run it from a different file,
ActiveWorkbookwill point to the wrong book. - Open the Visual Basic Editor. Press Alt+F11 (Windows) or go to Developer > Visual Basic (Mac: Developer > Visual Basic). If the Developer tab is hidden, right-click the ribbon and choose Customize the Ribbon to enable it.
- Insert a new module. In the Project Explorer, right-click your workbook name, choose Insert > Module. This creates a blank code window.
- Paste the refresh code. Type or paste the following procedure:
TheSub RefreshAllLinks() Dim links As Variant links = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks) If Not IsEmpty(links) Then ActiveWorkbook.UpdateLink Name:=links, Type:=xlLinkTypeExcelLinks End If End SubLinkSourcescall returns an array of all Excel link paths. TheIf Not IsEmptycheck prevents an error when the workbook has no links. - Run the macro. Press F5 while the cursor is inside the subroutine, or go back to Excel and use Developer > Macros, select RefreshAllLinks, and click Run. You should see Excel briefly update the linked cells.
- Confirm the refresh. Check a few cells that depend on the external workbook. If the values changed, the links updated. You can also open Data > Edit Links to see the last updated time.
- Save the workbook. Save as .xlsm to keep the macro. If you save as .xlsx, the code is lost.
Note: Menu labels can differ slightly by Excel version, device, or region. On Mac, the Edit Links dialog is under Data > Edit Links, but the VBA object model is the same.
Common Mistakes
- Using
ThisWorkbookinstead ofActiveWorkbook.ThisWorkbookrefers to the file containing the macro. If your macro lives in a personal workbook or an add-in, it will refresh the wrong file. UseActiveWorkbookor explicitly name the workbook. - Forgetting the
Typeargument.UpdateLinkneedsType:=xlLinkTypeExcelLinksfor Excel-to-Excel links. Omitting it can cause a runtime error or refresh the wrong link type. - Assuming all links are Excel links.
LinkSourcescan return OLE, DDE, or web links. ThexlLinkTypeExcelLinksfilter keeps only Excel file links. If you need to refresh other types, you must handle them separately. - Running the macro when source files are closed or moved. Excel cannot update a link to a file it cannot find. The macro will raise an error or leave old values. Always verify source paths first.
- Not checking for empty links. Calling
UpdateLinkon a workbook with no links returns an error. TheIsEmptyguard prevents that.
Tips
- To refresh links silently without the Update Values dialog, set
Application.DisplayAlerts = Falsebefore the update and restore it afterward. This suppresses prompts about updating links. - If you want to refresh links every time the workbook opens, place the
UpdateLinkcall in theWorkbook_Openevent in the ThisWorkbook module. That runs automatically when the file is opened. - Use
Application.Calculation = xlCalculationManualbefore refreshing and set it back toxlCalculationAutomaticafterward to speed up large workbooks. - Store source workbooks in a consistent folder structure. Relative paths are more portable than absolute paths, but Excel still needs the files present.
- Test the macro on a copy of the workbook first. Link updates can overwrite formulas if the source structure changed.
Troubleshooting
If the macro does not refresh the links, work through these checks in order:
- Check for errors. Press Ctrl+Break to stop a running macro, then step through with F8. The Immediate Window (Ctrl+G) can show the value of
links; if it is Empty, the workbook has no Excel links. - Verify link paths. Open Data > Edit Links. If a source shows as Error or Unchecked, click Change Source and point to the correct file. The macro cannot fix broken paths.
- Close and reopen the source files. If a source is open in another Excel instance, the link may be locked. Close it and retry.
- Check macro security. If macros are disabled, the code will not run. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and enable macros for the current session. Only do this for files you trust.
- Update Excel. An outdated build can have link-refresh bugs. Use the official update channel for your version.
- If the workbook is shared or on OneDrive, syncing conflicts can block updates. Open the file locally and retry.
If none of these work, the link may be to a non-Excel source (such as a web query or database). Those require their own refresh method, not UpdateLink.
Frequently Asked Questions
Can I refresh links without opening the source workbooks?
No. Excel must read the source file to update values. If the source is closed, Excel may use the last saved values but cannot fetch new ones. Keep sources accessible.
Does this work on Excel for Mac?
Yes. The VBA object model for links is the same on Mac. Use the same code in the Visual Basic Editor. Menu paths may differ slightly.
What if my workbook has links to multiple file types?
UpdateLink with xlLinkTypeExcelLinks handles only Excel file links. For OLE or DDE links, you must loop through LinkSources without the type filter and call UpdateLink for each, or refresh them manually via Edit Links.
Will refreshing links update all formulas?
Refreshing links updates the linked values, and dependent formulas recalculate automatically if calculation is automatic. If you set calculation to manual, press F9 after the refresh.
Can I schedule a link refresh?
VBA itself cannot run on a schedule. You can use Windows Task Scheduler to open the workbook and run a macro via a script, but that requires additional setup and is not covered here.
Why do I get a "Method 'UpdateLink' of object '_Workbook' failed" error?
That usually means the link name is invalid or the source file is missing. Check the array returned by LinkSources and confirm each path exists. Also ensure you passed the correct Type argument.