Quote:
Originally Posted by RobiNew
Many thanks, gmaxey! Your code returns an error on "bFound = .Execute"
and the message reads:
Run-time error '5560'
The Find What text contains an invalid expression.
Use search criteria
|
Robinew,
I suspect that is because of where you live (or your regional settings). Try:
Code:
Sub SelectNextURL()
Dim oDoc As Document, oRng As Range
Dim bFound As Boolean
Dim strLS As String
strLS = Application.International(wdListSeparator)
Set oDoc = ActiveDocument
Set oRng = oDoc.Range
With oRng.Find
.ClearFormatting
.Text = ""
.MatchWildcards = True
'Word wildcards: http[s]:// followed by any non-space characters
.Text = "(http*)(://*)([! ^13^32^9^t<>'""]{1" & strLS & "})"
bFound = .Execute
End With
If bFound Then
oRng.Select
MsgBox "URL found and selected: " & oRng.Text, vbInformation
Else
MsgBox "No URL found.", vbExclamation
End If
lbl_Exit:
Exit Sub
End Sub
or simplified:
Code:
Sub SelectNextURL()
Dim oDoc As Document, oRng As Range
Dim strLS As String
strLS = Application.International(wdListSeparator)
Set oDoc = ActiveDocument
Set oRng = oDoc.Range
With oRng.Find
.ClearFormatting
.Text = ""
.MatchWildcards = True
'Word wildcards: http[s]:// followed by any non-space characters
.Text = "(http*)(://*)([! ^13^32^9^t<>'""]{1" & strLS & "})"
If .Execute Then
oRng.Select
MsgBox "URL found and selected: " & oRng.Text, vbInformation
Else
MsgBox "No URL found.", vbExclamation
End If
End With
lbl_Exit:
Exit Sub
End Sub