Hello,
I found this code to update/change Excel's every sources I have on a Word document whenever the excel file is moved. The code works well, but it doesn't change the references located in the header/footer. Is there a way to tweak the code to update header as well?
Thank you for your time
JP
I found this code to update/change Excel's every sources I have on a Word document whenever the excel file is moved. The code works well, but it doesn't change the references located in the header/footer. Is there a way to tweak the code to update header as well?
VBA Code:
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
'create FileDialog object as File Picker dialog box
Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
With dlgSelectFile
'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
End If
End With
Set dlgSelectFile = Nothing
'update fields
fieldCount = ActiveDocument.Fields.Count
For x = 1 To fieldCount
ActiveDocument.Fields(x).LinkFormat.SourceFullName = newFile
Next x
End Sub
Thank you for your time
JP