View Single Post
 
Old 04-06-2021, 10:38 AM
Stephen Ray Stephen Ray is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Sep 2018
Location: Kansas
Posts: 34
Stephen Ray is on a distinguished road
Default

Thank you, Macropod,

This seems to be the key:
.Wrap = wdFindStop

Here's what I am going to use. This gives me the precision I want.
Previous to this code below, the Macro would Find "Organization:"
And highlight the remainder of line after the :colon.
This works if the highlighted part is at least one character longer than
"AFL of the CIO From Hawaii"
It will not find it if the highlighted part is exactly "AFL of the CIO From Hawaii"

Code:
With Selection.Find
    .Text = "AFL of the CIO From Hawaii"
    .ClearFormatting
    .Replacement.ClearFormatting
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
       With Selection.Find
           .ClearFormatting
           .Replacement.ClearFormatting
           .Text = "CIO"
           .Replacement.ClearFormatting
           .Replacement.Text = " CIB "
           .Execute Replace:=wdReplaceAll, Forward:=True, _
            Wrap:=wdFindStop
           Selection.Find.Execute Replace:=wdReplaceAll
           'the above line will work with =wdReplaceone   Same Results.
           Selection.Copy

'       Selection.HomeKey Unit:=wdLine
'       Selection.TypeText "Found IT"
'Else
'       Selection.TypeText "Did Not Find IT"
'       Selection.HomeKey Unit:=wdLine
       End With
 End If
Amazingly, "AFL of the CIB From Hawaii" is highlighted after this runs.
Reply With Quote