vba - Replace a word in text file with another word using macro -


The code below is a word for me ("this") in the second file ("he"). Likewise, I need to change another word in the same text file.

My requirement replaces the word "this" with "that" and replaces "to" with "to". Can you modify according to the code given below? Sub-ReplaceStringInFile () dim objFSO object dim as objFil object as obsolete object dim strfileName string dim strfolder string dims SstrAll string set form as objFSO = CreateObject In the form of ("script .filesystemobject") strfolder = "c: \ macro \" strfileName = Dir (strfolder & "* .txt") strfileName & lt; & Gt; VbNullString objFil = objFSO.opentextfile (StrFller and StrFileName) strAll = objFil.readall objFil.Close obzipil 2 = objFSO.createtextfile (strfolder and strfileName) Change objFil2.Write (strahll, "THIS", "THAT") set objFil2. This string changes "Line" itemprop = "text">

after the StrFileName = Dir loop End Sub

objFil2.Write change (strAll, "this", "that")

just add this line under:

  objFil2.Write (strAll, "to", "per")   

Edit:

Sorry, I did not test the code. Do this:

  sub-ReplaceStringInFile () as the obsolete objFSO object, as objFil object, the objFil2 object is named as StrFileName string, in the form of strFolder string, as strAll string , Set the newFileText string as objFSO = CreateObject ("scripting.filesystemobject") strfolder = "c: \ macro \" strfileName = Dir (strfolder & amp; "* .txt") strfileName & lt; & Gt; vbNullString set objFil = objFSO.opentextfile (StrFolder & amp; StrFileName) strAll = objFil.readall objFil.Close set objFil2 = objFSO.createtextfile (StrFolder & amp; StrFileName) 'that changed it to change newFileText = text (strAll, "this", "that") newFileText = to change the text to "change (newFileText," from "," to ") the new text objFil2.Write newFileText objFil2.Close StrFileName = Dir loop End with Sub   

Please tell me that it works.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -