Disable user interaction in a MS Word Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jstyle
    New Member
    • Oct 2007
    • 3

    Disable user interaction in a MS Word Macro

    I have a macro in MS Word that does several hundred find and replace statements. The problem is each time it does a find and replace it prompts me do you want to search from the begining. How do I write into the code to not prompt me each time it does a correction. Below is a small piece of the code. Thanks

    Sub Macro2()
    '
    ' Macro2 Macro
    '
    '
    Selection.Find. ClearFormatting
    Selection.Find. Replacement.Cle arFormatting
    With Selection.Find
    .Text = "Paragraph"
    .Replacement.Te xt = "PARA"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLik e = False
    .MatchAllWordFo rms = False
    End With
    Selection.Find. Execute Replace:=wdRepl aceAll
    With Selection.Find
    .Text = "period"
    .Replacement.Te xt = "PD"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLik e = False
    .MatchAllWordFo rms = False
    End With
    Selection.Find. Execute Replace:=wdRepl aceAll
    With Selection.Find
    .Text = "jump"
    .Replacement.Te xt = "JP"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLik e = False
    .MatchAllWordFo rms = False
    End With
    Selection.Find. Execute Replace:=wdRepl aceAll
    End Sub
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    dear,

    I think the WRAP must be excluded from the code or set to wdFindStop.

    The help in VBA is:

    Wrap Property
    See AlsoApplies ToExampleSpecif icsReturns or sets what happens if the search begins at a point other than the beginning of the document and the end of the document is reached (or vice versa if Forward is set to False) or if the search text isn't found in the specified selection or range. Read/write WdFindWrap.

    WdFindWrap can be one of these WdFindWrap constants.
    wdFindAsk After searching the selection or range, Word displays a message asking whether to search the remainder of the document.
    wdFindContinue The find operation continues when the beginning or end of the search range is reached.
    wdFindStop The find operation ends when the beginning or end of the search range is reached.

    expression.Wrap
    expression Required. An expression that returns a Find object.

    Example
    The following example searches forward through the document for the word "aspirin." When the end of the document is reached, the search continues at the beginning of the document. If the word "aspirin" is found, it's selected.

    Code:
    Sub WordFind()
        With Selection.Find
            .Forward = True
            .ClearFormatting
            .MatchWholeWord = True
            .MatchCase = False
            [B].Wrap = wdFindContinue[/B]
            .Execute FindText:="aspirin"
        End With
    End Sub
    br,

    Comment

    Working...