View Single Post
 
Old 05-19-2011, 07:16 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi samhdc,

Here are two macros for updating image links. They both handle inline and floating images. The first one processes all images in the document; the second one processes only the selected image(s).
Code:
Sub UpdateAllImageLinks()
Dim oShp As Shape, iShp As InlineShape, RngStry As Range, OldPath As String, NewPath As String
With ThisDocument
  For Each RngStry In .StoryRanges
    For Each oShp In RngStry.ShapeRange
      With oShp
        .Select
        If Not .LinkFormat Is Nothing Then
          OldPath = .LinkFormat.SourcePath
          NewPath = InputBox("Update Path", "Image Path Update", OldPath)
          If NewPath = "" And OldPath <> "" Then Exit Sub
          ' Replace the link to the external file if they differ.
          If OldPath <> NewPath Then
            .LinkFormat.SourceFullName = Replace(.LinkFormat.SourceFullName, OldPath, NewPath)
          End If
        End If
      End With
    Next oShp
    For Each iShp In .InlineShapes
      With iShp
        .Select
        If Not .LinkFormat Is Nothing Then
          OldPath = .LinkFormat.SourcePath
          NewPath = InputBox("Update Path", "Image Path Update", OldPath)
          If NewPath = "" And OldPath <> "" Then Exit Sub
          ' Replace the link to the external file if they differ.
          If OldPath <> NewPath Then
            .LinkFormat.SourceFullName = Replace(.LinkFormat.SourceFullName, OldPath, NewPath)
          End If
        End If
      End With
    Next iShp
  Next RngStry
End With
End Sub
Code:
Sub UpdateOneImageLink()
Dim oShp As Shape, iShp As InlineShape, RngStry As Range, OldPath As String, NewPath As String
With Selection
  For Each oShp In .ShapeRange
    With oShp
      If Not .LinkFormat Is Nothing Then
        OldPath = .LinkFormat.SourcePath
        NewPath = InputBox("Update Path", "Image Path Update", OldPath)
        If NewPath = "" And OldPath <> "" Then Exit Sub
        ' Replace the link to the external file if they differ.
        If OldPath <> NewPath Then
          .LinkFormat.SourceFullName = Replace(.LinkFormat.SourceFullName, OldPath, NewPath)
        End If
      End If
    End With
  Next oShp
  For Each iShp In .InlineShapes
    With iShp
      If Not .LinkFormat Is Nothing Then
        OldPath = .LinkFormat.SourcePath
        NewPath = InputBox("Update Path", "Image Path Update", OldPath)
        If NewPath = "" And OldPath <> "" Then Exit Sub
        ' Replace the link to the external file if they differ.
        If OldPath <> NewPath Then
          .LinkFormat.SourceFullName = Replace(.LinkFormat.SourceFullName, OldPath, NewPath)
        End If
      End If
    End With
  Next iShp
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote