The following macro will change the path (or part of the path) defined in
oldPath to the path (or part of the path) defined in newPath in the
hyperlinks of all the documents in a folder selected from the dialog
prompted by the macro. The particular macro will only change one path at a
time. If you have more than one path to change it is doable, but needs extra
code to process each field.
Only the link is changed. The macro does not change the display text. Try it
on a folder with copies of a couple of sample documents.
Sub ChangeFieldContent()
Dim strFileName As String
Dim strPath As String
Dim oDoc As Document
Dim iFld As Long
Dim oldPath As String
Dim newPath As String
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
oldPath = "D:\\My Documents" 'case sensitive
newPath = "D:\\My Documents\\Word Documents"
With fDialog
.Title = "Select Folder containing the documents to be modified and
click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFileName = Dir$(strPath & "*.doc")
While Len(strFileName) <> 0
Set oDoc = Documents.Open(strPath & strFileName)
For iFld = oDoc.Fields.Count To 1 Step -1
With oDoc.Fields(iFld)
If .Type = wdFieldHyperlink Then
If InStr(1, .Code, oldPath) <> 0 Then
.Code.Text = Replace(.Code.Text, _
oldPath, newPath)
End If
.Update
End If
End With
Next iFld
oDoc.Close SaveChanges:=wdSaveChanges
Set oDoc = Nothing
GetNextDoc:
strFileName = Dir$()
Wend
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>