Quote:
Originally Posted by gmayor
It may not be possible to do this in a single pass, without knowing what else is in the document, so I would suggest a sequential search e.g. as below. This should search the common story ranges in a document, but if not the coding gets more complicated to cover the less common ones, to which end I would suggest Document Batch Processes,
See also Replace using wildcards
Code:
Option Explicit
Sub Macro1()
Dim vFindText As Variant
Dim i As Long
Dim oStory As Range
vFindText = Array("25.222", "25.2666", "25.223")
For Each oStory In ActiveDocument.StoryRanges
For i = 0 To UBound(vFindText)
With oStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
Do While .Execute(findText:=vFindText(i))
oStory.HighlightColorIndex = wdTurquoise
oStory.Collapse 0
Loop
End With
Next i
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
For i = 0 To UBound(vFindText)
With oStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
Do While .Execute(findText:=vFindText(i))
oStory.HighlightColorIndex = wdTurquoise
oStory.Collapse 0
Loop
End With
Next i
Wend
End If
Next oStory
lbl_Exit:
Set oStory = Nothing
Exit Sub
End Sub
|
Is it possible to modify this code (or use a separate macro) to verify if a second number in a document exists at the same time?
For example, using one of the numbers above (25.222).
I would like to check the document IF 25.222 exists, THEN does a second specific number (entered by the user) exists in the document simultaneously. So if 25.222 is in the document, I need to know 25.2666 is also in the document at the same time.
Maybe as an output, both would be highlighted or if one or the other doesn't exist, then a false statement or no highlighting.
Is that possible?
Thanks ahead!
J