Hi guys! 
How are we all? Well i hope.
Quick summary: I am going through all ("*.txt") files in a folder and finding and replacing values from an excel list. I need to modify the code below so that I can do multiple find and replace.
The values to search for are in column "A" and the values to replace with are in column "B".
So far, I can only find and replace one value at a time. Any help would be much appreciated
Thanks in advance!
How are we all? Well i hope.
Quick summary: I am going through all ("*.txt") files in a folder and finding and replacing values from an excel list. I need to modify the code below so that I can do multiple find and replace.
The values to search for are in column "A" and the values to replace with are in column "B".
So far, I can only find and replace one value at a time. Any help would be much appreciated
Thanks in advance!
Code:
Sub ReplaceStringInFile()
'http://stackoverflow.com/questions/14840574/find-and-replace-string-in-all-excel-files-in-folder
Dim objFSO As Object
Dim objFil As Object
Dim objFil2 As Object
Dim StrFileName As String
Dim StrFolder As String
Dim SstrAll As String
Dim FindStr As String, ReplaceStr As String
FindStr = Range("a2").Value
ReplaceStr = Range("b2").Value
Set objFSO = CreateObject("scripting.filesystemobject") 'enable microsoft scripting runtime
StrFolder = "C:\test\" 'choose folder to go through
StrFileName = Dir(StrFolder & "*.txt") 'choose extension to find and replace
Do While StrFileName <> vbNullString
Set objFil = objFSO.opentextfile(StrFolder & StrFileName)
strAll = objFil.readall
objFil.Close
Set objFil2 = objFSO.createtextfile(StrFolder & StrFileName)
objFil2.Write Replace(strAll, FindStr, ReplaceStr) 'choose what to find and replace *case sensitive
objFil2.Close
StrFileName = Dir
Loop
End Sub