View Single Post
 
Old 12-02-2020, 09:56 PM
dinofanatic dinofanatic is offline Windows 10 Office 2019
Novice
 
Join Date: Nov 2020
Posts: 5
dinofanatic is on a distinguished road
Default

Thank you for your help! Got it working for the most part, aside from the footer.

This is the whole loop:
Code:
With ThisDocument
  For Each Rng In .StoryRanges
    ' Go through the shapes in the story range.
    For Each Shp In Rng.ShapeRange
      With Shp
        ' Skip over shapes that don't have links to external files.
        If Not .LinkFormat Is Nothing Then
          With .LinkFormat
            ' Replace the source filename with the new filename
            OldPath = Left(.SourceFullName, InStrRev(.SourceFullName, "\"))
            OldFile = .SourceName
            StrTmp = Replace(.SourceFullName, OldPath, NewPath)
            StrTmp = Replace(StrTmp, OldFile, NewFile)
            ' Replace the link to the external file if it differs.
            If OldPath <> NewPath Then
               .SourceFullName = StrTmp
              On Error Resume Next
              .AutoUpdate = False
              On Error GoTo 0
            End If
          End With
        End If
      End With
    Next Shp
    ' Go through the inlineshapes in the story range.
    For Each iShp In Rng.InlineShapes
      With iShp
        ' Skip over inlineshapes that don't have links to external files.
        If Not .LinkFormat Is Nothing Then
          With .LinkFormat
            ' Replace the source filename with the new filename
            OldPath = Left(.SourceFullName, InStrRev(.SourceFullName, "\"))
            OldFile = .SourceName
            StrTmp = Replace(.SourceFullName, OldPath, NewPath)
            StrTmp = Replace(StrTmp, OldFile, NewFile)
            ' Replace the link to the external file if it differs.
            If OldPath <> NewPath Then
               .SourceFullName = StrTmp
              On Error Resume Next
              .AutoUpdate = False
              On Error GoTo 0
            End If
          End With
        End If
      End With
    Next iShp
    ' Go through the fields in the story range.
    For Each Fld In Rng.Fields
      With Fld
        ' Skip over fields that don't have links to external files.
        If Not .LinkFormat Is Nothing Then
          With .LinkFormat
            ' Replace the source filename with the new filename
            OldPath = Left(.SourceFullName, InStrRev(.SourceFullName, "\"))
            OldFile = .SourceName
            StrTmp = Replace(.SourceFullName, OldPath, NewPath)
            StrTmp = Replace(StrTmp, OldFile, NewFile)
            ' Replace the link to the external file if it differs.
            If OldPath <> NewPath Then
               .SourceFullName = StrTmp
              On Error Resume Next
              .AutoUpdate = False
              On Error GoTo 0
            End If
          End With
        End If
      End With
    Next Fld
  Next Rng
  .Save
End With
Does the footer have to be specifically addressed as its own loop?
Reply With Quote