Search code examples
vbams-wordord

word dialogue box opens


This is my first post, I am not a programmer.

I built a Word macro (visual basic) that does a search and replace for many items (dates and numbers) within a highlighted block of text. Here's a single search and replace segment. It works well, but after each segment a Y/N dialogue box (in this case Word 2003) appears asking if I want to search the remainder of the document--I DONT.

Query: Is there anything I can add to macro that would respond "NO" (after each search and replace segment) as the macro runs so I don't have to select "no" after each of the 20 or so segments?

Typical segment:.

Selection.Find.ClearFormatting.
Selection.Find.Replacement.ClearFormatting.
With Selection.Find.
    .Text = "2015".
    .Replacement.Text = "2016".
    .Forward = True.
    .Wrap = wdFindAsk.
    .Format = False.
    .MatchCase = False.
    .MatchWholeWord = False.
    .MatchWildcards = False.
    .MatchSoundsLike = False.
    .MatchAllWordForms = False.
End With.
Selection.Find.Execute Replace:=wdReplaceAll

...

THX


Solution

  • The line

    .Wrap = wdFindAsk
    

    tells Word that you want it to ask the user whether to keep searching. Changing that line to

    .Wrap = wdFindStop
    

    should fix your problem.