Stop clearformatting in Record Macro RRS feed

  • Question

  • I record simple, little macros.  Usually the steps start with something like:


    (macro continues)

    I inadvertently changed something.  Now when I record the actions, the code starts with



    With Selection.find

    How do I turn off the first two lines and stop them automatically recording?

    Tuesday, August 29, 2017 12:38 AM

All replies

  • You can't. Those lines are added anytime you record a Find/Replace macro, but not otherwise. In a Find/Replace macro, they clear out any format settings left over from a previous Find/Replace and, hence, it's generally advisable to retain those lines. Even so, you could edit the recorded macro to delete them.

    Paul Edstein
    [MS MVP - Word]

    Tuesday, August 29, 2017 12:56 AM
  • Paul,

    Thank you for the fast response!  I have created many find replace macros. Recently found that prior words, searched elsewhere, were replaced in the current document. I searched for a way to clear the Word buffer, and somehow activated clearformatting. Why didn't it appear before, and how might I have turned it on? Would a command to clear the clipboard do this?

    Tuesday, August 29, 2017 2:09 AM
  • I have never recorded a Find/Replace macro where those two lines did not appear - even in a new blanl document where the recording was done immediately after starting Word! For example, I just did that and got:

    Sub Macro1()
    ' Macro1 Macro
      With Selection.Find
        .Text = "ABC"
        .Replacement.Text = "DEF"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    Paul Edstein
    [MS MVP - Word]

    • Proposed as answer by Steve Fan Friday, September 1, 2017 9:32 AM
    Tuesday, August 29, 2017 8:36 AM