![]() |
|
#7
|
||||
|
||||
|
Here are two simplified approaches you might try. The first highlights only those numbers that stand alone (e.g. Clause 23, but not Clause 2.2), whereas the second highlights both. Note the wildcard expressions used to capture both cases and plurals.
Code:
Sub DemoA()
Application.ScreenUpdating = False
Dim StrFndA As String, i As Long, Rng As Range
StrFndA = "[Cc]lause,[Pp]aragraph,[Pp]art,[Ss]chedule" 'highlight numbers after these words
For Each Rng In ActiveDocument.StoryRanges
With Rng
Select Case .StoryType
Case wdMainTextStory, wdFootnotesStory
For i = 0 To UBound(Split(StrFndA, ","))
With .Duplicate
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Text = Split(StrFndA, ",")(i) & "[s ]@[0-9]@>[. ][!0-9]"
End With
Do While .Find.Execute
.Start = .Words(2).Start
.End = .Words.First.End
.HighlightColorIndex = wdBrightGreen
.Collapse wdCollapseEnd
Loop
End With
Next
Case Else
End Select
End With
Next Rng
Application.ScreenUpdating = True
End Sub
Code:
Sub DemoB()
Application.ScreenUpdating = False
Dim StrFndA As String, i As Long, Rng As Range
StrFndA = "[Cc]lause,[Pp]aragraph,[Pp]art,[Ss]chedule" 'highlight numbers after these words
StrFndB = "minute,hour,day,week,month,year,working,business" 'highlight numbers before these words
For Each Rng In ActiveDocument.StoryRanges
With Rng
Select Case .StoryType
Case wdMainTextStory, wdFootnotesStory
For i = 0 To UBound(Split(StrFndA, ","))
With .Duplicate
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Text = Split(StrFndA, ",")(i) & "[s ]@[0-9.]{1,}"
End With
Do While .Find.Execute
.Start = .Words(2).Start
.HighlightColorIndex = wdYellow
.Collapse wdCollapseEnd
Loop
End With
Next
Case Else
End Select
End With
Next Rng
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Highlight numbers after a specific word in numbered list
|
liblikas90 | Word VBA | 3 | 02-27-2019 03:52 AM |
| How to highlight lines containing specific words | SixStringSW | Word VBA | 4 | 06-03-2018 03:57 PM |
| How to find (highlight) two and more words in a list of 75k single words in Word 2010 | Usora | Word | 8 | 05-29-2018 03:34 AM |
| Search a cell that contains words and numbers and convert the numbers to metric | Carchee | Excel Programming | 36 | 10-08-2014 03:16 PM |
VBA to highlight words if used too much
|
aolszewski | Word VBA | 3 | 11-23-2013 02:07 AM |