#1
|
||||
|
||||
How to insert hyperlink based on text
I apologize for asking the solution of previously answered question here as I am not able to work around with this.
Please merge it if required. I have Number like this. Quote:
[/QUOTE]http://pimg-faiw.uspto.gov/fdd/00/2015/92/029/0.pdf[/QUOTE] I want to find Code:
([US]{2}) ([0-9]{4})([0-9]{3})([0-9]{2})([0-9]{2}) Code:
([US]{2}) ([0-9]{4})([0-9]{3})([0-9]{2})([0-9]{2}) I want to keep US 20150299200 as it is. |
#2
|
||||
|
||||
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] |
#3
|
||||
|
||||
This is really great.
I have many other pattern for Hyperlink. I think there should be no problem now. |
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 |
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 |