Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-05-2015, 02:47 AM
PRA007's Avatar
PRA007 PRA007 is offline How to insert hyperlink based on text Windows 7 32bit How to insert hyperlink based on text Office 2010 32bit
Competent Performer
How to insert hyperlink based on text
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default 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:
US 20150299200
I want to insert hyperlink to it like this way

[/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})
and insert hyperlink like this.

Code:
([US]{2}) ([0-9]{4})([0-9]{3})([0-9]{2})([0-9]{2})

I want to keep US 20150299200 as it is.
Reply With Quote
  #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: 21,963
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
  #3  
Old 11-05-2015, 05:30 AM
PRA007's Avatar
PRA007 PRA007 is offline How to insert hyperlink based on text Windows 7 32bit How to insert hyperlink based on text Office 2010 32bit
Competent Performer
How to insert hyperlink based on text
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

This is really great.
I have many other pattern for Hyperlink. I think there should be no problem now.
Reply With Quote
Reply

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 11:23 AM.


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