View Single Post
 
Old 05-12-2017, 12:58 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Paul is correct. I had assumed hyperlink fields, but the general premise will work for Link fields e.g.
Code:
Function ReplaceLink(oDoc As Document)
    On Error GoTo err_Handler
    Dim oRng As Range
    Dim oFld As Field
    ActiveWindow.View.ShowFieldCodes = True
    For Each oFld In oDoc.Fields
        If oFld.Type = wdFieldLink Then
            If InStr(1, oFld.code, "Project 1") > 0 Then
                Set oRng = oFld.code
                oRng.Text = Replace(oRng.Text, "Project 1", "Project 2")
                oFld.code = oRng
                oFld.Update
            End If
        End If
    Next oFld
    ActiveWindow.View.ShowFieldCodes = False
    ReplaceLink = True
lbl_Exit:
    Exit Function
err_Handler:
    ReplaceLink = False
    Err.Clear
    Resume lbl_Exit
End Function
It works with links I have created and changes the field using your data so it should work for you. Call it from the add-in as a Custom Process using the name ReplaceLink in the dialog. Test it on one document open in Word before batch processing
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote