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
    2016-04-04T23:35:12+00:00

    I'm late to this discussion...but.

    I've got issues implementing this, almost EXACTLY.

    Here's where it falls down for me. I'm running this on Office 2016, Mac version - which should work, regardless. The table doc is the SR2CTm.dotm. The path in sFname is the correct drive path.

    But where it spits out an error is the Set oChanges = Documents.Open(fileName:=sFname, Visible:=False) section. Each time I do this, it comes back with "named argument not found" and cites the visible:=False component.

    Help?

    Sub TableSR()

    '

    ' TableSR Macro

    '

    '

     Dim oChanges As Document, oDoc As Document

     Dim oTable As Table

     Dim oRng As Range

     Dim rFindText As Range, rReplacement As Range

     Dim i As Long

     Dim sFname As String

     'Change the path in the line below to reflect the name and path of the table document

     sFname = "/Users/brian/macros/tablemacro.dotm"

     Set oDoc = ActiveDocument

     Set oChanges = Documents.Open(fileName:=sFname, Visible:=False)

     Set oTable = oChanges.Tables(1)

     For i = 1 To oTable.Rows.Count

         Set oRng = oDoc.Range

         Set rFindText = oTable.Cell(i, 1).Range

         rFindText.End = rFindText.End - 1

         Set rReplacement = oTable.Cell(i, 2).Range

         rReplacement.End = rReplacement.End - 1

         Selection.HomeKey wdStory

         With oRng.Find

                 .ClearFormatting

                 .Replacement.ClearFormatting

                 .MatchWildcards = True

                 .Text = rFindText.Text

                 .Replacement.Text = rReplacement.Text

                 .Forward = True

                 .Wrap = wdFindContinue

                 .Execute Replace:=wdReplaceAll

           End With

    Next i

    oChanges.Close wdDoNotSaveChanges

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Paul Edstein 82,871 Reputation points Volunteer Moderator
    2016-04-05T02:39:44+00:00

    Try deleting:

    , Visible:=False

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-04-05T17:49:24+00:00

    Unfortunately no, now it throws a bug that says:

    Run-time error '5174':

    This file could not be found.

    Try one or more of the following:

    * Check the spelling of the name of the document.

    * Try a different file name.

     (/Users/brian/macros/tablemacro.dotm)

    And the problem with THAT is that the directory is correct; it's pointing right at it. So either the directory structure is looking for something it's not finding, or...

    Was this answer helpful?

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more