Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found my answer <a href="http://answers.microsoft.com/en-us/office/forum/office_2007-word/changing-word-link-source-via-vba-resets-update/643d118a-a467-e011-8dfc-68b599b31bf5?rtAction=1383333293556" rel="nofollow">here</a> - this code asks for the location of the new Excel file and updates all of the field codes of the Excel linked tables.</p> <p>The code from that link is below.</p> <pre><code>Public Sub changeSource() Dim dlgSelectFile As FileDialog 'FileDialog object ' Dim thisField As Field Dim selectedFile As Variant 'must be Variant to contain filepath of selected item Dim newFile As Variant Dim fieldCount As Integer ' Dim x As Long On Error GoTo LinkError 'create FileDialog object as File Picker dialog box Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker) With dlgSelectFile .Filters.Clear 'clear filters .Filters.Add "Microsoft Excel Files", "*.xls, *.xlsb, *.xlsm, *.xlsx" 'filter for o nly Excel files 'use Show method to display File Picker dialog box and return user's action If .Show = -1 Then 'step through each string in the FileDialogSelectedItems collection For Each selectedFile In .SelectedItems newFile = selectedFile 'gets new filepath Next selectedFile Else 'user clicked cancel Exit Sub End If End With Set dlgSelectFile = Nothing 'update fields With ActiveDocument fieldCount = .Fields.Count For x = 1 To fieldCount With .Fields(x) 'Debug.Print x ' Debug.Print .Type If .Type = 56 Then 'only update Excel links. Type 56 is an excel link .LinkFormat.SourceFullName = newFile ' .Update .LinkFormat.AutoUpdate = False DoEvents End If End With Next x End With MsgBox "Source data has been successfully imported." Exit Sub LinkError: Select Case Err.Number Case 5391 'could not find associated Range Name MsgBox "Could not find the associated Excel Range Name " &amp; _ "for one or more links in this document. " &amp; _ "Please be sure that you have selected a valid " &amp; _ "Quote Submission input file.", vbCritical Case Else MsgBox "Error " &amp; Err.Number &amp; ": " &amp; Err.Description, vbCritical End Select End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload