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: Oldest
  1. Anonymous
    2011-12-05T03:16:22+00:00

    Here is a free commercial :-)

    http://gregmaxey.mvps.org/VBA_Find_And_Replace.htm

    Graham knows this.  His code will only work in the main text story range (or whatever storyrange has the selection).

    Was this answer helpful?

    0 comments No comments
  2. Charles Kenyon 171K Reputation points Volunteer Moderator
    2011-12-05T06:07:40+00:00

    I recommend that you first run it on a copy of the document until you are comfortable with the changes the macro makes and that you always run it with tracked changes turned on.

    Pam

    Thanks for the warning. Yes, I am only running it copies until I am fully confident of the outcome. I'm actually running on vba code copied into a document, then taking the translated code which is unreadable and putting it back into a copy of the vba module. I test each procedure after doing this. So far I haven't had a successful run. I will keep at it until I get unreadable code that will work. May take a while.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-12-05T12:49:39+00:00

    Pam,

    I received two postmaster errors when I tried to reply to your feedback.  You use the features of the Add-In to set options like "Use Wildcards, Match Case, etc."

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-12-05T19:39:29+00:00

    Thanks for letting me know.  I've posted again to the website with my corrected email address.

    Pam

    Was this answer helpful?

    0 comments No comments