Share via

Multiple "replace all" across 5 folders

Anonymous
2022-08-10T09:40:53+00:00

Hi everyone,

I'm not very computer literate so bear with me.

I've got approx 150 word docs (all only 2 or 3 pages long) across 4 folders.

As an example, I've now been told that each APPLE I have in these docs, must now be written as Apple.

Is there a way I can do a "replace all" on each APPLE to become Apple - or do I need to manually open every 150 docs and do a cut and paste?

Thank you all so much in advance (please tell me it's possible or I'm going to be sitting here in front of my computer until dawn :)

Cheers,

amanda

Microsoft 365 and Office | Word | For business | Other

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

3 answers

Sort by: Most helpful
  1. Charles Kenyon 167.8K Reputation points Volunteer Moderator
    2022-08-10T11:27:22+00:00

    Hans has given you a macro.

    Here are two free Add-Ins that can do this from the user interface. Both act on one folder at a time.

    Was this answer helpful?

    0 comments No comments
  2. HansV 462.6K Reputation points
    2022-08-10T10:13:04+00:00

    Start Word so that you have a new empty document.

    Press Alt+F11 to activate the Visual Basic Editor.

    Select Insert > Module.

    Copy the code listed below into the module.

    Edit the code as indicated - you need to specify the words to be found and replaced, and the folder paths.

    With the insertion point anywhere in the code, press F5 to run the code.

    Switch back to Word.

    If you want to keep the code for later use, save the empty document as a macro-enabled document (.docm).

    You'll have to allow macros if you reopen it later.

    Sub ReplaceMany()
        ' Change the constants as needed
        Const ReplaceWhat = "APPLE"
        Const ReplaceWith = "Apple"
        Dim Folders As Variant
        Dim Folder As Variant
        Dim File As String
        Dim Doc As Document
        Application.ScreenUpdating = False
        ' Change the paths to the folders containing your documents
        Folders = Array("C:\Word\Folder1", "C:\Word\Folder2", _
                        "C:\Word\Folder3", "C:\Word\Folder4")
        ' Loop through the folders
        For Each Folder In Folders
            ' Add path separator if necessary
            If Right(Folder, 1) <> Application.PathSeparator Then
                Folder = Folder & Application.PathSeparator
            End If
            ' Get first file name
            File = Dir(PathName:=Folder & "*.doc*")
            ' Loop through the files
            Do While File <> ""
                ' Open document
                Set Doc = Documents.Open(FileName:=Folder & File, AddToRecentFiles:=False)
                ' Replace text
                Doc.Content.Find.Execute FindText:=ReplaceWhat, MatchCase:=True, _
                    MatchWholeWord:=True, ReplaceWith:=ReplaceWith, Replace:=wdReplaceAll
                ' Save and close document
                Doc.Close SaveChanges:=True
                ' Get the next file name
                File = Dir
            Loop
        Next Folder
        Application.ScreenUpdating = True
    End Sub
    

    Was this answer helpful?

    0 comments No comments
  3. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2022-08-10T09:57:24+00:00

    See, for example: https://www.msofficeforums.com/159681-post25.html. By running the 'Main' macro there, all files in a given folder and its sub-folders will be processed. The actual find/replace expressions go in the Update(Rng As Range) sub.

    Was this answer helpful?

    0 comments No comments