The following modification of Doug's macro will allow the user to pick the
new link file and will update the filed to show the new result.
The error message is caused when during the replacement the double slashes
in the path are replaced by single slashes. The modification also addresses
that issue.
Sub UpdateLinks()
' Macro created 26/10/01 by Doug Robbins to update links in a document
' With mods 21/10/08 by Graham Mayor to select file.
Dim alink As Field, linktype As Range, linkfile As Range
Dim linklocation As Range, i As Integer, j As Integer, linkcode As Range
Dim Message, Title, Newfile
Dim fDialog As FileDialog
Dim counter As Integer
counter = 0
For Each alink In ActiveDocument.Fields
If alink.Type = wdFieldLink Then
Set linkcode = alink.Code
i = InStr(linkcode, Chr(34))
Set linktype = alink.Code
linktype.End = linktype.Start + i
j = InStr(Mid(linkcode, i + 1), Chr(34))
Set linklocation = alink.Code
linklocation.Start = linklocation.Start + i + j - 1
If counter = 0 Then
Set linkfile = alink.Code
linkfile.End = linkfile.Start + i + j - 1
linkfile.Start = linkfile.Start + i
Message = "Select new link file and click OK"
Title = "Update Link"
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.Title = Message
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , Title
Exit Sub
End If
Newfile = fDialog.SelectedItems.Item(1)
Newfile = Right(Newfile, Len(Newfile) - InStrRev(Newfile,
"\"))
End With
End If
linkcode.Text = linktype & Newfile & linklocation
counter = counter + 1
alink.Update
End If
Next alink
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>