![]() |
#6
|
||||
|
||||
![]()
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] |
|