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

I tried to use your code , but it seemed unable to trim the unwanted punctuations.
For example,
Code:
Roa, Felipe Suescun de, Comments on the ICSID Award Saipem v. Bangladesh: Would its rationale be applicable in future cases?, INT'L INST. FOR CONFLICT PREVENTION & RESOL. (May 5, 2011), http://www.cpradr.org/news-publications/articles/2011-05-05-comments-on-the-icsid-award-saipem-v-bangladesh-would-its-rationale-be-applicable-in-future-cases-2011-writing-contest-winner.
This url-text cannot be recognized correctly, still includes the last period.

Code:
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 "[!:;.,?})]" 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