Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-18-2020, 05:52 AM
savvy savvy is offline new to vba - go to end of sub Windows 10 new to vba - go to end of sub Office 2016
Novice
new to vba - go to end of sub
 
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
 

Tags
nubie, search and replace



Other Forums: Access Forums

All times are GMT -7. The time now is 07:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft