Public gcolWords As Collection
Public Const kDirCELL = "C1"
Public Sub FixAllFiles()
Dim vDir
vDir = Range(kDirCELL).Value
If vDir = "" Then
MsgBox "No folder given in " & kDirCELL
Else
RemoveKeywordsFromAllFiles vDir
End If
End Sub
'del all keywords in list in all worksheets in all files
Private Sub RemoveKeywordsFromAllFiles(ByVal pvDir)
Dim ws As Worksheet
Dim vFil, vTargT
Dim i As Integer
Dim fso
Dim oFolder, oFile
'get all keywords
Set gcolWords = New Collection
Range("A2").Select
While ActiveCell.Value <> ""
gcolWords.Add ActiveCell.Value
ActiveCell.Offset(1, 0).Select 'next row
Wend
If gcolWords.Count = 0 Then
MsgBox "No keywords assigned"
Exit Sub
End If
'cycle thru all files
On Error GoTo errRun
If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(pvDir)
For Each oFile In oFolder.Files
If InStr(oFile.Name, ".xls") > 0 Then 'ONLY DO EXCEL FILES
Workbooks.Open oFile
For Each ws In Sheets
ws.Activate
ReplaceWords
Next
ActiveWorkbook.Close True
End If
Next
Set ws = Nothing
Set gcolWords = Nothing
MsgBox "done"
Exit Sub
errRun:
MsgBox Err.Description, , Err
End Sub
Private Sub ReplaceWords()
Dim i As Integer
Dim wrd
For i = 1 To gcolWords.Count
wrd = gcolWords(i)
Range("A1").Select
Cells.Replace What:=wrd, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next
End Sub