Consulting

Results 1 to 5 of 5

Thread: Find/Replace Text across multiple documents located in same folder

  1. #1

    Find/Replace Text across multiple documents located in same folder

    I am brand new to creating macros in Word. I located something online that I think is a good start to what I am trying to accomplish, "https://word.tips.net/T003783_Changing_Information_in_Multiple_Documents.html". However I do get an error when I run the macro, "run-time error '5111' This command is not available on this platform". I am on a Windows 7 machine on Word 2016. The highlighted line is "With Application.FileSearch".

    Here is the macro:

    Sub Mass_Find()
    '
    ' Mass_Find Macro
    '
    '
    Public Sub MassReplace()
    With Application.FileSearch
    .LookIn = "C:\Users\Doug\Desktop\TERMED COBRA - Copy (2)" ' where to search
    .SearchSubFolders = True ' search the subfolders
    .FileName = "*.doc" ' file pattern to match

    ' if more than one match, execute the following code
    If .Execute() > 0 Then
    ' for each file you find, run this loop
    For i = 1 To .FoundFiles.Count
    ' open the file based on its index position
    Documents.Open FileName:=.FoundFiles(i)

    ' search and replace the address
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "Doug"
    .MatchCase = True
    .Replacement.Text = "Becky"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ' replace e-mail address
    'With Selection.Find
    '.Text = "Oldemail"
    '.Replacement.Text = "Newemail"
    'End With
    'Selection.Find.Execute Replace:=wdReplaceAll

    ' save and close the current document
    ActiveDocument.Close wdSaveChanges
    Next i
    Else
    ' if the system cannot find any files
    ' with the .doc extension
    MsgBox "No files found."
    End If
    End With
    End Sub

    The other things I am interested in doing is how to change the text string search, or the location when these criteria changes.

    Thanks,

    Will

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,046
    Location
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Thank you Greg. This is exactly what I am looking for. Upon downloading the two templates- all I see are the header and footnotes without any code. See attachment below. Am I missing something?
    Attached Images Attached Images

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,870
    Location
    Application.FileSearch was deprecated over a decade ago.

    See also:
    http://www.vbaexpress.com/forum/show...l=1#post312637
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,046
    Location
    You load the template as an add-in and the interface appears on the ribbon add-ins tab.
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •