link from simular post:
http://stackoverflow.com/questions/38034325/vb-i-need-to-include-a-whole-string-in-search
i have a word doc with phone numbers, need to make every instance of sip:00000 0000 0000 ( 0s being the phone number) active this code works half way only activating the sip: how do i include the whole number for example Sip:00000 0000 0000 it will mostly be the 15 numbers with spaces but sometimes there may not be a space or there could be less or more numbers just need every thing on that line to be active for example
FARM EQUIPMENT
Contact:Mr. Peter lay
Sip:00000 0000 0000 <<--just this line active in the whole doc of over 100 each one has unique number
Email:[email protected]
Code
Sub FindAndHyperlink()
'define the style
Dim strStyle As String
strStyle = "Subtle Emphasis"
'set the search range
Dim rngSearch As Range
Set rngSearch = ActiveDocument.Range
'set the search string
Dim strSearch As String
strSearch = "sip:"
'set the target address for the hyperlink
Dim strAddress As String
strAddress = "sip:"
With rngSearch.Find
Do While .Execute(findText:=strSearch, MatchWholeWord:=True, Forward:=True) = True
With rngSearch 'we will work with what is found as it will be the selection
ActiveDocument.Hyperlinks.Add Anchor:=rngSearch, Address:=strAddress
.Style = ActiveDocument.Styles(strStyle) 'throw the style on it after the link
End With
rngSearch.Collapse Direction:=wdCollapseEnd
'keep it moving
Loop
End With
End Sub
Display More