View Single Post
 
Old 08-18-2020, 05:52 AM
savvy savvy is offline Windows 10 Office 2016
Novice
 
Join Date: Aug 2020
Location: Toronto
Posts: 23
savvy is on a distinguished road
Default new to vba - go to end of sub

In this simple search for a word, I want to end the sub if the word is not in the document and not type Regards.

Sub Macro2()
'
' Macro2 Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find.Font
.Bold = False
.Italic = False
End With
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
End With
With Selection.Find
.Text = "test"
.Replacement.Text = "test replaced"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine


Selection.TypeText Text:= _
"Regards,"

End Sub
Reply With Quote