Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2015, 05:33 AM
PRA007's Avatar
PRA007 PRA007 is offline How to insert hyperlink based on the text Windows 7 32bit How to insert hyperlink based on the text Office 2010 32bit
Competent Performer
How to insert hyperlink based on the text
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default How to insert hyperlink based on the text

Hi,
I was searching on the net if it is possible to find specific text and then convert it to hyperlink for example



I have patent number
US 20140343287 A1

I would like to insert hyperlink to the text
the formate for inserting hyperlink is based on what we find without space

like
https://www.google.co.in/patents/US20140343287A1?cl=en

or any formate i desire which will be the same only the text will be replace

I was able to make the link using find and replace funciton of word.

Find what
([A-Z]{2}) ([0-9]{4,}) ([A-Z0-9]{1,2})
Replace with
https://www.google.co.in/patents/\1\2\3?cl=en
Reply With Quote
  #2  
Old 05-08-2015, 07:08 AM
gmayor's Avatar
gmayor gmayor is offline How to insert hyperlink based on the text Windows 7 64bit How to insert hyperlink based on the text Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can do it with a macro

Code:
Sub AddHLink()
Dim oRng As Range
Dim strLink As String
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(FindText:="([A-Z]{2}) ([0-9]{4,}) ([A-Z0-9]{1,2})", MatchWildcards:=True)
            strLink = oRng.Text
            strLink = Replace(strLink, Chr(32), "")
            strLink = "https://www.google.co.in/patents/" & strLink & "?cl=en \t _blank"
            oRng.Text = ""
            ActiveDocument.Fields.Add oRng, wdFieldHyperlink, strLink, False
            oRng.Fields.Update
            oRng.Collapse 0
        Loop
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
http://www.gmayor.com/installing_macro.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-10-2015, 09:55 PM
PRA007's Avatar
PRA007 PRA007 is offline How to insert hyperlink based on the text Windows 7 32bit How to insert hyperlink based on the text Office 2010 32bit
Competent Performer
How to insert hyperlink based on the text
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default Working Fine but I made mistake in asking.

Apology for not making it clear what I wanted.
Actually I want Original text to be intact. just want to insert hyperlink to the text (patent Numbers).
I made one more step after your macro, converted it back to the original text.

find what:
https://www.google.co.in/patents/([A-Z]{2})([0-9]{4,})([A-Z0-9]{1,2})?cl=en
Replaced with:
\1 \2 \3

Final text retained the link. Thanks
Reply With Quote
  #4  
Old 05-11-2015, 01:11 AM
gmayor's Avatar
gmayor gmayor is offline How to insert hyperlink based on the text Windows 7 64bit How to insert hyperlink based on the text Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you want to use the original string as the display text then modify the original macro as follows:

Code:
Sub AddHLink()
Dim oRng As Range
Dim strLink As String
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(FindText:="([A-Z]{2}) ([0-9]{4,}) ([A-Z0-9]{1,2})", MatchWildcards:=True)
            strLink = oRng.Text
            strLink = Replace(strLink, Chr(32), "")
            strLink = "https://www.google.co.in/patents/" & strLink & "?cl=en \t _blank"
            ActiveDocument.Hyperlinks.Add Anchor:=oRng, _
                                          Address:=strLink, _
                                          TextToDisplay:=oRng.Text
            oRng.End = oRng.Fields(1).Result.End
            oRng.Collapse 0
        Loop
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
microsoft word, vba, wildcard



Similar Threads
Thread Thread Starter Forum Replies Last Post
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 the text Insert the Hyperlink and hide all sheets except clicking Hyperlink PRADEEPB270 Excel 1 02-22-2013 09:47 AM
Hyperlink/Data Insert & replace jclinton Word 1 09-19-2012 07:22 PM
Insert Hyperlink - Differing Functionality nell3773 Word 0 04-30-2010 12:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:14 PM.


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