View Single Post
 
Old Today, 09:36 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,629
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Quote:
Originally Posted by RobiNew View Post
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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote