Edit Links in MS Word Field Codes


On the night of May 25, I described how to use a macro in MS Word to automatically insert hyperlinks. When done this way the links are listed in field codes. See figures 1 and 2 below. The field codes can be toggled on and off by pressing ALT + F9. If you need to redirect the links (for example, if your links are directed to a network folder and need to be changed to be active on the local drive of an attorney's laptop while she's offline), you can find and replace the file paths in the field codes. See Fig. 3 below. Note that you need to add in double backslashes between folders in the file path.

Before moving on you should confirm that this actually works. I have seen field codes updated perfectly well using this simple find and replace method, but I have also seen (in the same version of Word, with links added with the same macro) the field codes get updated, but the actual hyperlinks remain the same. If this happens use this macro (from Jay Freedman here ) instead:

Sub ReplaceHyperlinks() Dim HL As Hyperlink Dim target As String Dim repl As String

target = InputBox("Find address", "Replace Hyperlink") If Len(target) = 0 Then Exit Sub

repl = InputBox("Replace address", "Replace Hyperlink") If Len(repl) = 0 Then Exit Sub

For Each HL In ActiveDocument.Hyperlinks With HL If InStr(LCase(.Address), LCase(target)) _ Or InStr(LCase(.TextToDisplay), LCase(target)) Then .Address = Replace(.Address, target, repl) .TextToDisplay = Replace(.TextToDisplay, target, repl) .ScreenTip = Replace(.ScreenTip, target, repl) .Range.Fields.Update End If End With Next End Sub

Just insert it as is in a new module and run it. It will prompt you for the file path you want to replace, and then ask you again to input the file path you want to insert. See Figure 4 below. This will successfully update both the field codes and the hyperlinks.