View Single Post
 
Old 10-03-2023, 01:50 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Question Add hyperlink to each http(s) string

The macro here below works perfectly when the string is followed by a space. How do I modify the code so as to make it work also when the string is followed by , ; . : etc.? Can someone help?


Code:
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.MoveStartUntil ("http")
    Rng.MoveEndUntil Cset:=" "
    Link = Rng.Text
      ActiveDocument.Hyperlinks.Add Anchor:=Rng, _
      Address:=Link, _
      SubAddress:="", ScreenTip:="", TextToDisplay:=Rng.Text
      Rng.Font.Color = 15597568 'codice di Word
    Rng.Collapse wdCollapseStart
Loop
End With
Reply With Quote