Link to home
Start Free TrialLog in
Avatar of rreiss60
rreiss60Flag for United States of America

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.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    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
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial