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
    2015-02-25T08:59:42+00:00

    I realise this is a very old thread, but I needed a multiple find and replace (F&R) macro that dealt with 100+ wildcard F&R routines. This macro appears to work very well, but perhaps too well in my case. In case it matters, I'm using Word 2010.

    I created a doc with a single 2-column table with 'find' routines in the left column and 'replace' routines in the right. I used the wildcard syntax as I run all these as wildcard F&R routines. For example, I had a routine to search for a number followed by a space followed by a month name--in wildcard speak that's something like ([0-9])( )(May). I wanted to replace it with the same text except for the space, which I wanted as a non-breaking space; i.e. \1^s\3. 

    I changed three lines in the macro -- the one that pointed to my Word doc containing the table, the 'MatchWholeWord' to False, and the 'MatchWildcards' to True. I changed nothing else.

    I added this slightly revised macro to a macros.dotm doc I store in my Word>STARTUP folder. And then I opened a large doc and ran the macro on it. After several minutes, it was finished. However, everything that was searched for was replaced by the ACTUAL text in the 'replace' column, and Word didn't consider it as wildcard syntax.

    The macro correctly searched for all instances in the first column, using the wildcard syntax. But the text it replaced it with ignored the wildcard setting and went in as \1^s\3. So instead of 9 May being replaced with 9<non-breaking space>May, it got replaced with \1^s\3.

    I also tried putting parentheses around the elements in the replace syntax--i.e. ( \1)(^s)(\3)--but again, it just went in as that text, and not as I would've expected had I done a Ctrl+H F&R routine with wildcards checked.

    Can anyone help? What line(s) do I need to add/change/delete in the macro for it to read the contents of the 'replace' column as wildcard syntax, and not as text?

    Thanks!

    --Rhonda

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. 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
  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. 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