I want to perform a Find/Replace on a directory of Excel files. Open each file, Find/Replace, Save, close.
This code works as a "one-off"
Sub Find_Replace1()Range("A2:A100000").Replace What:="MyTextString1", Replacement:="MyTextString2"End Sub
I have this code which saves a directory of .csv files to .xls I'd like to change that function to the Find/Replace above.
If there is a better way, that works too....
Apologies, I do not know how to get the code to display formatted correctly! Can someone tell me how and I will report the code...
Here is the other code:
Sub CSVtoXLS() 'UpdatebyExtendoffice20170814 Dim xFd As FileDialog Dim xSPath As String Dim xCSVFile As String Dim xWsheet As String Application.DisplayAlerts = False Application.StatusBar = True xWsheet = ActiveWorkbook.Name Set xFd = Application.FileDialog(msoFileDialogFolderPicker) xFd.Title = "Select a folder:" If xFd.Show = -1 Then xSPath = xFd.SelectedItems(1) Else Exit Sub End If If Right(xSPath, 1) <> "" Then xSPath = xSPath +"" xCSVFile = Dir(xSPath & "*.csv") Do While xCSVFile <> "" Application.StatusBar = "Converting: " & xCSVFile Workbooks.Open Filename:=xSPath & xCSVFile ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xlsx", vbTextCompare), xlWorkbookDefault ActiveWorkbook.Close Windows(xWsheet).Activate xCSVFile = Dir Loop Application.StatusBar = False Application.DisplayAlerts = True End SubSub CSVtoXLS() 'UpdatebyExtendoffice20170814 Dim xFd As FileDialog Dim xSPath As String Dim xCSVFile As String Dim xWsheet As String Application.DisplayAlerts = False Application.StatusBar = True xWsheet = ActiveWorkbook.Name Set xFd = Application.FileDialog(msoFileDialogFolderPicker) xFd.Title = "Select a folder:" If xFd.Show = -1 Then xSPath = xFd.SelectedItems(1) Else Exit Sub End If If Right(xSPath, 1) <> "" Then xSPath = xSPath +"" xCSVFile = Dir(xSPath & "*.csv") Do While xCSVFile <> "" Application.StatusBar = "Converting: " & xCSVFile Workbooks.Open Filename:=xSPath & xCSVFile ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xlsx", vbTextCompare), xlWorkbookDefault ActiveWorkbook.Close Windows(xWsheet).Activate xCSVFile = Dir Loop Application.StatusBar = False Application.DisplayAlerts = True End Sub