View Single Post
 
Old 11-05-2015, 03:33 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If you want to find text like:
US 20150299200
there is no point using a Find expression like:
([US]{2}) ([0-9]{4})([0-9]{3})([0-9]{2})([0-9]{2})
for hyperlink insertion purposes. Amongst other things, that could get false matches with strings like SU 12345678901, SS 12345678901 or UU 12345678901. Simply use:
US [0-9]{11}
Having found the string, you will need to parse it to get the required hyperlink format and your Find expression has no effect on that. The parsing is quite simple.
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrTxt As String
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "US [0-9]{11}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    StrTxt = Split(.Text, " ")(1)
    StrTxt = Right(StrTxt, 2) & "/" & Left(StrTxt, 4) & "/" & Mid(StrTxt, 8, 2) & "/" & Mid(StrTxt, 5, 3)
    .Hyperlinks.Add Anchor:=.Duplicate, Address:="http://pimg-faiw.uspto.gov/fdd/" & StrTxt & "/0.pdf", TextToDisplay:=.Text
    .End = .Fields(1).Result.End
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote