rreiss60
asked on
If/then statement for a find/replace in word vba
Want to run an if/then something like this in Word VBA:
Pseudocode:
If find/replace doesn't find anything to replace then
do something else e.g. msgbox("Nothing found.")
Got this far with basic find/replace:
Selection.Find.ClearFormat ting
Selection.Find.Replacement .ClearForm atting
With Selection.Find
.Text = "TextToFind"
.Replacement.Text = "ReplacementText"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Pseudocode:
If find/replace doesn't find anything to replace then
do something else e.g. msgbox("Nothing found.")
Got this far with basic find/replace:
Selection.Find.ClearFormat
Selection.Find.Replacement
With Selection.Find
.Text = "TextToFind"
.Replacement.Text = "ReplacementText"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.