View Single Post
 
Old 10-17-2021, 04:25 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,994
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There may be a more elegant way to do this but this is my initial thoughts on how to solve it
Code:
Sub ChickenOrEgg()
  Dim aRng As Range, rngHigh As Range, rngTurq As Range  
  Set aRng = Selection.Range
  aRng.End = ActiveDocument.Range.End
  With aRng.Find
    .ClearFormatting
    .Highlight = True
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    If .Execute Then Set rngHigh = aRng.Duplicate
  End With
  
  Set aRng = Selection.Range
  aRng.End = ActiveDocument.Range.End
  With aRng.Find
    .ClearFormatting
    .Font.ColorIndex = wdTurquoise
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    If .Execute Then Set rngTurq = aRng.Duplicate
  End With
  
  If rngHigh Is Nothing Then
    If rngTurq Is Nothing Then
      MsgBox "No hits for either"
    Else
      rngTurq.Select
    End If
  Else
    If rngTurq Is Nothing Then
      rngHigh.Select
    Else
      If rngHigh.Start < rngTurq.Start Then
        rngHigh.Select
      Else
        rngTurq.Select
      End If
    End If
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote