Hi, everybody! Can someone help? I'm trying to find and select the whole string of a passive URL. Here below my tentative code, which stops too soon.
Code:
Sub SelectNextURL()
Dim rng As Range
Dim startPos As Long
Dim endPos As Long
Dim doc As Document
Dim urlPattern As String
Dim found As Boolean
Set doc = ActiveDocument
'URLs starting with http or https
urlPattern = "(https?://[^\s<>""']+)"
' Use the Find object
Set rng = doc.Content
With rng.Find
.ClearFormatting
.Text = ""
.MatchWildcards = True
' Word wildcards: http[s]:// followed by any non-space characters
.Text = "(http*)(://*)([! ^13^32^9^t<>'""]@)"
found = .Execute
End With
If found Then
rng.Select
MsgBox "URL found and selected: " & rng.Text, vbInformation
Else
MsgBox "No URL found.", vbExclamation
End If
End Sub