Page 17 of 17 FirstFirst ... 7151617
Results 241 to 243 of 243
  1. #241
    New Lounger
    Join Date
    Feb 2019
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by macropod View Post
    Try replacing the UpdateFields macro with:
    Code:
    Private Sub UpdateFields()
    ' This routine sets the new path for external links, pointing them to the current folder.
    Dim Rng As Range, Fld As Field, Shp As Shape, iShp As InlineShape, i As Long, NewPath As String
    ' Go through all story ranges in the document.
    With ThisDocument
      NewPath = .Path & "\"
      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
                  .SourceFullName = NewPath & .SourceName
                  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
                  .SourceFullName = NewPath & .SourceName
                  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
                  .SourceFullName = NewPath & .SourceName (runtime error 5360)
                  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
    End Sub
    Hi Paul

    Thanks for having a look at this. I replace the Private Sub Updatefieds() code with your new code. The red highlights above were block compile errors so I removed those lines but then it got stuck on a runtime error 5360.

  2. #242
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,255
    Thanks
    2
    Thanked 484 Times in 393 Posts
    Try deleting the three problem 'End If' lines. Code updated
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #243
    New Lounger
    Join Date
    Feb 2019
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by macropod View Post
    Try deleting the three problem 'End If' lines. Code updated
    Hi Paul.

    I had deleted those three lines previously which cleared those issues but the row:
    .SourceFullName = NewPath & .SourceName
    is causing problems.

    Even if I remove all existing links and paste in a new link, without messing around with duplicating folders etc, the code runs into a problem on that line. I think somehow the NewPath reference isn't correct or it's changing the path format and is breaking the code. The path is showing as the https://d.docs.live.net/xxxxxxxxxxxxx onedrive location to the original linked excel file rather than the folder path to the current word file.

    Code:
    Private Sub UpdateFields()
    ' This routine sets the new path for external links, pointing them to the current folder.
    Dim Rng As Range, Fld As Field, Shp As Shape, iShp As InlineShape, i As Long, NewPath As String
    ' Go through all story ranges in the document.
    With ThisDocument
    NewPath = .Path & ""
    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
    .SourceFullName = NewPath & .SourceName
    On Error Resume Next
    .AutoUpdate = False
    On Error GoTo 0
    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
    .SourceFullName = NewPath & .SourceName
    On Error Resume Next
    .AutoUpdate = False
    On Error GoTo 0
    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
    .SourceFullName = NewPath & .SourceName [The code is getting stuck here. NewPath displays the long https:// onedrive link. .SourceName displays the correct filename.]
    On Error Resume Next
    .AutoUpdate = False
    On Error GoTo 0
    End With
    End If
    End With
    Next Fld
    Next Rng
    .Save
    End With
    End Sub

Page 17 of 17 FirstFirst ... 7151617

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •