![]() |
#2
|
||||
|
||||
![]()
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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Dragging a selection to copy it, not to move it | wardw | Word VBA | 2 | 11-28-2019 11:09 AM |
![]() |
Bumba | Excel Programming | 6 | 11-19-2019 08:50 AM |
![]() |
GuitarForLife | Word VBA | 7 | 02-09-2018 01:59 PM |
Search a folder to move an email to | koolman31 | Outlook | 0 | 02-11-2016 10:29 AM |
![]() |
paik1002 | Word VBA | 1 | 12-17-2015 04:51 AM |