Use a File Picker to Change Excel Link Paths in a Word Macro
Question details
Create a Word VBA macro that lets users browse for a replacement Excel workbook instead of typing its path.

- Product
- Microsoft Word VBA and linked Excel workbooks
- Device & OS
- not provided
- Scenario
- A Word document contains linked fields that need to point to a replacement Excel file.
- Observed behavior
- The user wants to select a workbook through a file picker and apply its path to the linked Excel fields.
Open the Word document and locate the replacement Excel workbook. Check that its linked sheet and item names match those expected by the document; the macro changes the source file, not the linked items.
Use a Word VBA file picker to relink Excel fields
Choose an Excel workbook in a file dialog and apply its path to Excel LINK fields in the document.
This macro uses each field's LinkFormat.SourceFullName property rather than asking the user to type a path. It changes all Excel LINK fields it finds in the document's story ranges, so use it only when they should all point to the same replacement workbook.
The macro targets LINK fields, not every possible embedded object or link stored in a drawing or text box. Review any other links separately.
In desktop Word, open the document, press Alt+F11, and select Insert > Module in the VBA editor. Add the module to the document or a template where you want to store the macro.
Paste this code into the module: Sub BrowseForExcelLink() Dim picker As FileDialog Dim chosenPath As String Dim story As Range, currentRange As Range Dim fld As Field Dim oldPath As String, ext As String Dim relinked As Long, problems As Long Set picker = Application.FileDialog(msoFileDialogFilePicker) With picker .Title = "Select the replacement Excel workbook" .AllowMultiSelect = False .Filters.Clear .Filters.Add "Excel workbooks", "*.xlsx; *.xlsm; *.xlsb; *.xls" If .Show <> -1 Then Exit Sub chosenPath = .SelectedItems(1) End With For Each story In ActiveDocument.StoryRanges Set currentRange = story Do While Not currentRange Is Nothing For Each fld In currentRange.Fields If fld.Type = wdFieldLink Then oldPath = "" On Error Resume Next Err.Clear oldPath = fld.LinkFormat.SourceFullName If Err.Number <> 0 Then problems = problems + 1 Err.Clear On Error GoTo 0 If InStrRev(oldPath, ".") > 0 Then ext = LCase$(Mid$(oldPath, InStrRev(oldPath, "."))) If ext = ".xlsx" Or ext = ".xlsm" Or ext = ".xlsb" Or ext = ".xls" Then On Error Resume Next Err.Clear fld.LinkFormat.SourceFullName = chosenPath If Err.Number = 0 Then relinked = relinked + 1 fld.Update If Err.Number <> 0 Then problems = problems + 1 Else problems = problems + 1 End If Err.Clear On Error GoTo 0 End If End If End If Next fld Set currentRange = currentRange.NextStoryRange Loop Next story MsgBox relinked & " Excel field(s) relinked. " & problems & " problem(s) reported." End Sub
Return to Word, open View > Macros, select BrowseForExcelLink, and choose Run. In the file picker, select the replacement workbook and click Open. Canceling the picker leaves the links unchanged.
Review the document's linked content and the macro's result message. If a field did not update, check that the replacement workbook contains the expected source item, then select the field and press F9 to try updating it.
On Windows, use File > Options > Quick Access Toolbar, choose Macros from the command list, and add BrowseForExcelLink. The toolbar button runs the macro and opens the file picker.

Work with Word documents and Excel files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Office files. Its format compatibility can make moving everyday documents and spreadsheets straightforward. The Word VBA macro above is specific to Microsoft Word and should not be assumed to run in WPS Office.

Frequently Asked Questions
What happens if I cancel the file picker?
The macro exits when you click Cancel, without changing any link paths.
Will this macro change links to multiple Excel workbooks?
Yes. It redirects every Excel LINK field it finds in the document's story ranges to the selected workbook. If different fields need different source workbooks, modify the macro to identify the intended old path before replacing it.
Why does a linked field still show an error after relinking?
The replacement workbook may not contain the sheet, range, or item referenced by the field. Check the source item in Excel, then select the field in Word and press F9 to update it.
How can I make the macro available from a button?
In Word for Windows, go to File > Options > Quick Access Toolbar, choose Macros, and add BrowseForExcelLink. Clicking that toolbar button opens the file picker.
Can I use this macro to change embedded Excel objects?
The macro targets Word LINK fields whose source filenames have Excel extensions. Embedded objects and other links that are not LINK fields need a separate approach.




