![]() |
|
#1
|
|||
|
|||
![]()
I think everything will depend on the number of '.' and ':' in each specific url. In https://www.msofficeforums.com/word-vba there's one colon and two periods/full stops, so the colon to find will be the second one and the period to find will be the 3rd one. Other urls may have different numbers of '.' and ':', which means that the code should take into account all posiible options. But that's impossible. At least I dont' know how to solve this. Besides, as far as I know urls may also include ',' and ';', so they also should be included in the code to be on the safe side. As a way out, it is possible to move rng's end (Cset) until space, and if it is preceded by '.,:;' move rng's end one char to the left, then add a hyperlink. Something like this:
Sub Hlink_https() 'Add hyperlinks to all http(s) in the active doc. Dim Rng As range Dim SearchString As String Dim Link As String Set Rng = ActiveDocument.range SearchString = "http" With Rng.Find .MatchWildcards = True Do While .Execute(FindText:=SearchString, Forward:=False) = True Rng.MoveEndUntil Cset:=" " If Rng.Characters.Last Like "[,.:;]" Then Rng.MoveEnd unit:=wdCharacter, count:=-1 End If Link = Rng.text ActiveDocument.Hyperlinks.Add Anchor:=Rng, _ Address:=Link, _ SubAddress:="", ScreenTip:="", TextToDisplay:=Rng.text Rng.Collapse wdCollapseStart Loop End With End Sub Last edited by vivka; 10-03-2023 at 12:44 PM. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
http/1.0 404 not found | Powerpoint User | PowerPoint | 2 | 11-20-2016 11:10 PM |
Find whether string contains hyperlink and Process the same | PRA007 | Word VBA | 15 | 12-01-2015 02:57 AM |
Multiple Hyperlink to a single string | PRA007 | Word VBA | 7 | 11-09-2015 04:29 PM |
Outlook http server | joelwelford | Outlook | 0 | 09-07-2015 10:00 AM |
![]() |
omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |