A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Here you go:
Sub ReplaceInFolder()
' ************** Change the constants as needed ***************
Const ListSheet = "List" ' sheet with the find and replace text
Const FindCol = "A" ' column with the find text
Const ReplaceCol = "B" ' column with the replacement text
Const FirstRow = 2 ' first row with find/replacement text
' *************************************************************
Dim wshList As Worksheet
Dim r As Long
Dim LastRow As Long
Dim strPath As String
Dim strFile As String
Dim wbk As Workbook
Dim wsh As Worksheet
Dim strFind As String
Dim strReplace As String
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
strPath = .SelectedItems(1)
Else
MsgBox "No folder selected!", vbExclamation
Exit Sub
End If
End With
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
Application.ScreenUpdating = False
' Set reference to the sheet with the find and replace text
Set wshList = ThisWorkbook.Worksheets(ListSheet)
' Determine the last used row in the column with the find text
LastRow = wshList.Cells(wshList.Rows.Count, FindCol).End(xlUp).Row
strFile = Dir(strPath & "*.xls*")
' Loop through the workbooks
Do While strFile <> ""
' Open workbook
Set wbk = Workbooks.Open(Filename:=strPath & strFile, AddToMRU:=False)
' Loop through the worksheets
For Each wsh In wbk.Worksheets
' Loop through the rows with find and replace text
For r = FirstRow To LastRow
strFind = wshList.Cells(r, FindCol).Value
strReplace = wshList.Cells(r, ReplaceCol).Value
' Replace
wsh.Cells.Replace What:=strFind, Replacement:=strReplace, _
LookAt:=xlWhole, MatchCase:=False
Next r
Next wsh
' Close and save workbook
wbk.Close SaveChanges:=True
strFile = Dir
Loop
Application.ScreenUpdating = True
End Sub