View Single Post
 
Old 07-18-2016, 07:25 AM
Robert K S Robert K S is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Jul 2016
Location: Cleveland, Ohio
Posts: 10
Robert K S is on a distinguished road
Default

Thanks--

Follow-up question: why "declare" the rng variable rather than just always use Selection.Range? (1) It seems like extra code and (2) it actually seems to break the script.

For example, if I do this,

Code:
With Selection.Range.Find ' Get rid of any stricken-through text
    .ClearFormatting 'Is this needed?
    .Replacement.ClearFormatting 'Is this needed?
    .Text = "*"
    .MatchWildcards = True
    .Font.StrikeThrough = True
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
End With
With Selection.Range.Find ' Get rid of any underlining
    .Font.Underline = wdUnderlineSingle
    .Replacement.Font.Underline = wdUnderlineNone
    .MatchWildcards = False
    .Text = ""
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
End With
It works as expected, but if I do this:

Code:
Dim rng As Range
Set rng = Selection.Range
With rng.Find ' Get rid of any stricken-through text
    .ClearFormatting 'Is this needed?
    .Replacement.ClearFormatting 'Is this needed?
    .Text = "*"
    .MatchWildcards = True
    .Font.StrikeThrough = True
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
End With
With rng.Find ' Get rid of any underlining
    .Font.Underline = wdUnderlineSingle
    .Replacement.Font.Underline = wdUnderlineNone
    .MatchWildcards = False
    .Text = ""
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
End With
It doesn't get rid of the underlining.
Reply With Quote