Announcement

Collapse
No announcement yet.

MS WORD HELP - text find and replace

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MS WORD HELP - text find and replace

    I have approx 300 files in a directory, and I want to change one piece of text in every one of them.

    There must be an easy way to do this, because doing it manually will take roughly eleventy bajillion hours.

    Any gurus out there?
    For LAMS information and resources - http://www.perthstreetbikes.com/foru...thread-156358/
    For LAMS discussion and to ask questions - http://www.perthstreetbikes.com/foru...thread-143289/

  • #2
    edit - am not a guru n re read it

    Comment


    • #3
      are you changing multiple lines?
      or just one?

      Edit: does it include links?
      "In all the human societies we have ever reviewed, in every age and in every state, there has seldom if ever been a shortage of eager young males prepared to kill and die to preserve the security, comfort and prejudices of their elders, and what you call heroism is just an expression of this fact; there is never a scarcity of idiots." -The Culture

      Comment


      • #4
        Just one line, no links

        Currently it reads:
        "Company name
        A division of <company A>"

        I need to change them all to read
        "Company name
        A division of <company B>"
        For LAMS information and resources - http://www.perthstreetbikes.com/foru...thread-156358/
        For LAMS discussion and to ask questions - http://www.perthstreetbikes.com/foru...thread-143289/

        Comment


        • #5
          Can you make macros for word?
          If cleanliness is next to godliness, why was jesus a dirty sandal-wearing beardo?

          Comment


          • #6
            Right

            Create a new macro, edit it

            replace the whole lot with this:

            Code:
            Public Sub BatchReplaceAll()
            Dim FirstLoop As Boolean
            Dim myFile As String
            Dim PathToUse As String
            Dim myDoc As Document
            Dim Response As Long
            Dim i As Long
            
            'Enter the directory you want to search here.
            PathToUse = "c:test"
            
            On Error Resume Next
            
            'Closes all open documents before beginning
            Documents.Close savechanges:=wdPromptToSaveChanges
            
            FirstLoop = True
            
            'Set the directory and type of file to batch process
            With Application.FileSearch
            .NewSearch
            .LookIn = PathToUse
            'INCLUDE SUBFOLDERS?
            .SearchSubFolders = True
            .FileName = "*.doc"
            .MatchTextExactly = True
            .FileType = msoFileTypeAllFiles
            
            If .Execute() Then
            For i = 1 To .FoundFiles.Count
            
            'Open document
            Set myDoc = Documents.Open(.FoundFiles(i))
            
            'Here are two examples of the search and replace code.
            'The first searches for text, the second searches for a link.
            'You have to hit Alt-F9 to show field codes before starting the
            'macro to search for links.
            Selection.Find.ClearFormatting
            Selection.Find.Replacement.ClearFormatting
            With Selection.Find
            .Text = "Replace Me"
            .Replacement.Text = "This was replaced."
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            End With
            Selection.Find.Execute Replace:=wdReplaceAll
            
            
            'These two lines update the field codes you just updated. They
            'aren't necessary if you're not searching for links.
            Selection.WholeStory
            Selection.Fields.Update
            
            
            'Close the modified document after saving changes
            myDoc.Close savechanges:=wdSaveChanges
            
            Next i
            End If
            End With
            End Sub
            Backup all docs just in case.. store some where this script won't touch.

            replace c:\test with your dir of choice.

            replace "Replace Me" with "<whatever you want>"

            replace "This was replaced" with "<desired change>"

            This replace is not case sensitive

            save macro(close it)

            run macro

            et voila.


            *shamelessly ripped(and truncated) from here: How can I find and replace text in multiple files? | Ask Metafilter

            Edit: you'll need relevant backslashes in the path(the code quoter seems to have removed one)
            Last edited by Kryzaach; 28-08-2009, 02:25 PM.
            "In all the human societies we have ever reviewed, in every age and in every state, there has seldom if ever been a shortage of eager young males prepared to kill and die to preserve the security, comfort and prejudices of their elders, and what you call heroism is just an expression of this fact; there is never a scarcity of idiots." -The Culture

            Comment


            • #7
              Aha! I knew a macro would do it, but no way i could be bothered wrtiting one.
              If cleanliness is next to godliness, why was jesus a dirty sandal-wearing beardo?

              Comment


              • #8
                Thank you
                For LAMS information and resources - http://www.perthstreetbikes.com/foru...thread-156358/
                For LAMS discussion and to ask questions - http://www.perthstreetbikes.com/foru...thread-143289/

                Comment


                • #9
                  no probs, let us know how you go with it, apparently it can take some time depending on the file size..

                  I tested it with some chunky ones here and it went through them pretty quickly, but YMMV.
                  "In all the human societies we have ever reviewed, in every age and in every state, there has seldom if ever been a shortage of eager young males prepared to kill and die to preserve the security, comfort and prejudices of their elders, and what you call heroism is just an expression of this fact; there is never a scarcity of idiots." -The Culture

                  Comment


                  • #10
                    or use EditPlus - it'll go thru multiple files and batch replace text

                    Comment


                    • #11
                      try using ULTRA EDIT. it has a function like that where you can replace text in a whole bunch of docs

                      Comment


                      • #12
                        Originally posted by Kryzaach View Post
                        no probs, let us know how you go with it, apparently it can take some time depending on the file size..

                        I tested it with some chunky ones here and it went through them pretty quickly, but YMMV.

                        Add
                        Code:
                        Selection.[B]NoProofing[/B] = True
                        As you replace each phrase, it re-starts the spell checker. Turn it off for the selection will speed things up considerably.

                        D'Art

                        Comment

                        Working...
                        X