My file is big with 10 million rows
I want to accomplish Find and replace multiple sting operations
Can this be done in vba without uploading in excel?
Then save the edited file in asked folder name ?
My file is big with 10 million rows
I want to accomplish Find and replace multiple sting operations
Can this be done in vba without uploading in excel?
Then save the edited file in asked folder name ?
There isn't a whole lot of information given but this should be possible with a custom script. I've written similar scripts in C# but you can with VBA as well to access your file and adjust the data.
Again, without knowing what type of file it is and what you want done specifically, it is a very broad question to answer.
Its a text file !!
Richard Buttrey
RIP - d. 06/10/2022
If any of the responses have helped then please consider rating them by clicking the small star iconbelow the post.
I am only posting this as a demonstration that this can be done. I am by no means stating that this will work for anything other than my small test I have done with the code.
- It will ask for the source file path
- It will ask for a full path for the output file it's going to create
- It will ask the string you want to find. I used "test"
- It will ask the string you want to replace it with. I used "TEST"
- It will ask you if there's a delimiter between data in the rows
- It will process the data until it's done. (I was too lazy to add any error checking which is the reason for the disclaimer below)
VERY BIG DISCLAIMER: USE AT YOUR OWN RISK
If you want to test this, I suggest copying the file and run the test on a duplicate so the original remains unaffected.
Macro:
Input File:![]()
Dim FilePath As String Dim FilePathTo As String Dim findthis As String Dim replwiththis As String Dim delimiter As String FilePath = InputBox("What is the full path of your .txt file?") If Dir(FilePath) = "" Then MsgBox "File does not exist, exiting" End End If FilePath2 = InputBox("What do you want to call the output file? (new file)") If Dir(FilePath2) <> "" Then MsgBox "File Already Exists, exiting" End End If findthis = InputBox("What value do you want to find?") replwiththis = InputBox("What value do you want to replace it with?") delimiter = InputBox("What is the delimiter? (Enter nothing if none)") Open FilePath2 For Output As #1 Open FilePath For Input As #2 Do Until EOF(2) Line Input #2, LineFromFile Dim newline As String LineItems = Split(LineFromFile, delimiter) If UBound(LineItems) >= 0 Then For i = LBound(LineItems) To UBound(LineItems) If LineItems(i) = findthis Then LineItems(i) = replwiththis End If Next i newline = Join(LineItems, delimiter) Print #1, newline Else If Len(LineFromFile) < 1 Then Print #1, "" Else Print #1, LineFromFile End If End If Loop Close #2 Close #1 MsgBox ("Done")
Output File:![]()
test,test1,test2,test3 test4,test5,test4,test3 test2,test1,test,test
![]()
TEST,test1,test2,test3 test4,test5,test4,test3 test2,test1,TEST,TEST
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks