View Single Post
 
Old 02-17-2016, 11:25 PM
PRA007's Avatar
PRA007 PRA007 is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default Working with Selection.range.

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
I want to replace ActiveDocument.Range with selection.range
Tried Replace ActiveDocument.Range with selection.range and oRng.End = oRng.End + 1 But don't have proper knowledge.
Reply With Quote