View Single Post
 
Old 03-24-2015, 12:57 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

You could use something like
Code:
Sub AddHyperlink(oDoc As Document, _
                 strText As String, _
                 strLink As String)
Dim oTable As Table
Dim oRng As Range
    Set oTable = oDoc.Tables(1)
    Set oRng = oTable.Range
    With oRng.Find
        Do While .Execute(FindText:=strText)
            oDoc.Hyperlinks.Add Anchor:=oRng, _
                                Address:=strLink, _
                                SubAddress:="", _
                                ScreenTip:="", _
                                TextToDisplay:=oRng.Text, _
                                Target:=""
            oRng.Collapse 0
            Exit Do
        Loop
    End With
lbl_Exit:
    Exit Sub
End Sub
and call that sub from the original code e.g.

Code:
AddHyperlink ActiveDocument, "Test A", "http:\\www.gmayor.com\WordPages.htm"
You can add any of the other parameters that you require.
__________________
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