Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-05-2015, 03:33 AM
macropod's Avatar
macropod macropod is offline How to insert hyperlink based on text Windows 7 64bit How to insert hyperlink based on text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
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
 

Tags
word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert hyperlink based on the text PRA007 Word VBA 3 05-11-2015 01:11 AM
VBA Search Table for Text/Select Text/Insert Hyperlink sldrellich Word VBA 3 03-24-2015 01:09 PM
Insert a hyperlink in body of email ChuckDrago Outlook 0 06-28-2013 06:51 AM
How to insert hyperlink based on text Insert the Hyperlink and hide all sheets except clicking Hyperlink PRADEEPB270 Excel 1 02-22-2013 09:47 AM
How to insert a hyperlink in activex textbox Joe Patrick Word VBA 1 10-03-2011 06:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:43 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft