Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-17-2016, 11:25 PM
PRA007's Avatar
PRA007 PRA007 is offline Working with Selection.range. Windows 7 64bit Working with Selection.range. Office 2010 32bit
Competent Performer
Working with Selection.range.
 
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
 

Tags
word vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with Selection.range. 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
Working with Selection.range. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:33 AM.


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