![]() |
|
#1
|
||||
|
||||
|
I have trouble finding answer to how to work this perfectly working macro with selection.range.
Code:
Sub AddGPHLink9()
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 = "website" & strLink & ".com"
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
Tried Replace ActiveDocument.Range with selection.range and oRng.End = oRng.End + 1 But don't have proper knowledge. |
| Tags |
| word vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Search and reduce the range of a text selection
|
paik1002 | Word VBA | 1 | 12-17-2015 04:51 AM |
| Selection (range) in Word or Excel table | NobodysPerfect | Word VBA | 2 | 09-16-2014 12:06 AM |
Selection.EndKey not working in 2010
|
Smallweed | Word VBA | 4 | 08-19-2014 07:21 AM |
| Selection or Range | Tommes93 | Word VBA | 1 | 04-10-2014 02:50 AM |
| Range Name in Adv Filter -> NOt working | 56_kruiser | Excel | 2 | 11-20-2012 09:58 AM |