View Single Post
 
Old 07-30-2018, 05:51 AM
henrychang henrychang is offline Windows 10 Office 2016
Novice
 
Join Date: Jul 2018
Posts: 5
henrychang is on a distinguished road
Default

Thank you very much!!
It really saved me a lot of time!
I revised the code a little bit as below:

Quote:
Sub ConvertURLTextsToHyperlinksInDoc()
Dim wdRng As Range
For Each wdRng In ActiveDocument.StoryRanges
With wdRng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "htt[ps]{1,2}://[!^13^t^l ]{1,}"
.Replacement.Text = ""
.Forward = True
.Format = False
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
If .Characters.Last Like "." Or .Characters.Last Like ";" Then .End = .End - 1
.Hyperlinks.Add .Duplicate, .Text, , , .Text
.Start = .Hyperlinks(1).Range.End
.Find.Execute
Loop
End With
Next
End Sub
Reply With Quote