View Single Post
 
Old 07-06-2015, 07:23 AM
Fed77 Fed77 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2015
Location: Venice
Posts: 5
Fed77 is on a distinguished road
Default

I tried to follow your suggestion but something is not working.
I'm not able to find out a correct form to express linkformat.sourcefullname with sections...
Could you help me?
Code:
Sub Update_link()
'
' Update_link Macro
'
Dim oStory As Range
Dim oField As Field
Dim section As section
Dim HdFt As HeaderFooter
Dim dlgSelectFile As FileDialog 'Filedialog Object
Dim thisFiled As Field
Dim selectedFile As Variant ' contain filepath of selected item
Dim newfile As Variant
Dim fieldCount As Integer, FldInx As Integer, k As Integer
Dim myRange As Range
'
'create FileDialog object as File picker Dialog boz
'
Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
'
With dlgSelectFile
  ' use Show method to dispaly File Picker dialog box and return user's action
  If .Show = -1 Then
  'step throug 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
'
With ActiveDocument
  For Each oStory In ActiveDocument.StoryRanges
    fieldCount = oStory.Fields.Count
    FldInx = 1
    While FldInx < fieldCount
      On Error Resume Next
      oStory.Fields(FldInx).LinkFormat.SourceFullName = newfile
      On Error GoTo 0
      FldInx = FldInx + 1
    Wend
  Next oStory
  '
  For Each section In ActiveDocument.Sections
    For Each HdFt In section.Headers
      Set myRange = HdFt.Range
      For Each aField In myRange.Fields
        aField.LinkFormat.SourceFullName = newfile
      Next aField
    Next HdFt
  Next section
End With
'
End Sub

Last edited by macropod; 07-06-2015 at 01:43 PM. Reason: Added code tags & formatting
Reply With Quote