macro for performing more than one find and replace procedure at the same time

Anonymous
2010-08-07T18:21:24+00:00

ok, i've got to about 700!! find and replace procedures for a document of TWO MILLION words so this macro could save me about 4 hours of work.

i tried to rewrite this macro so that it would work but it didn't.  can anyone help me out

Sub Macro1()

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " mit der "
.Replacement.Text = " mitder"
.Text = " mit dem "
.Replacement.Text = " mitdem"
.Text = " mit den "
.Replacement.Text = " mitden"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2010-08-07T18:56:51+00:00

ok, i got it work, i just copied it over

Sub Macro1()

'

' Macro1 Macro

' Macro recorded 8/7/10 by Seely Foley

'

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find

        .Text = " mit der "

        .Replacement.Text = " mitder"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = False

        .MatchCase = False

        .MatchWholeWord = False

        .MatchWildcards = False

        .MatchSoundsLike = False

        .MatchAllWordForms = False

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting

    Selection.Find.Replacement.ClearFormatting

    With Selection.Find

        .Text = " mit den "

        .Replacement.Text = " mitden"

        .Forward = True

        .Wrap = wdFindContinue

        .Format = False

        .MatchCase = False

        .MatchWholeWord = False

        .MatchWildcards = False

        .MatchSoundsLike = False

        .MatchAllWordForms = False

    End With

    Selection.Find.Execute Replace:=wdReplaceAll

End Sub

Was this answer helpful?

30+ people found this answer helpful.
0 comments No comments

53 additional answers

Sort by: Newest
  1. Anonymous
    2016-09-13T19:25:33+00:00

    Hi again,

    I'd like to ask your help with adapting this marvelous macro in two additional ways. I've tried doing it myself with poor results.

    Here are the two adaptations:

    1. Macro to remove periods from acronyms. I developed this as an array macro in this thread: 

    http://answers.microsoft.com/en-us/msoffice/forum/msoffice\_word-mso\_win10/macro-for-editing-acronyms/46d7b361-a8d5-4cf2-b0dd-f10c45ab3034

    As I kept working on it, though, I ended up with a find array with more than 200 search terms. So I'd like to adapt this macro such that the table consists of just one column, providing the "find what" items, which are in turn processed with the period-deleting routine. That routine, however, is a Do While block in my original macro, and that's the part I don't know how to adapt here. Also: using this macro with changes tracked is not an issue in this case.

    1. Macro to insert comments. Here's the thread I originally posted:

    http://answers.microsoft.com/en-us/msoffice/forum/msoffice\_word-mso\_win10/array-macro-for-adding-comments/b5303931-7852-4e85-b288-18cb0f017894

    Again, however, as I worked on this, the number of search terms and the length of comments ballooned beyond what I thought they'd be, and the processing became pretty slow. So for this one, I'm thinking there could be two columns, with the search terms on the left and the text of the corresponding comment on the right.

    Many thanks for your help...

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-08-21T01:28:02+00:00

    Thanks, that's helpful.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-08-20T05:21:09+00:00

    Add a line

    DoEvents

    immediately before

    Next lngIndex

    which should eliminate the Not Responding message (though it should in any case complete).

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-08-19T06:50:29+00:00

    Thanks so much! It works well, although it does lock up Word with a "Not Responding" message before it finishes. I guess that's understandable given how many searches I made it execute.

    Was this answer helpful?

    0 comments No comments