Rabidurbian
-
Total Posts
:
4
- Scores: 0
-
Reward points
:
0
- Joined: 12/29/2010
-
Status: offline
|
VBA script to change some lines in text file.
Tuesday, January 04, 2011 1:36 AM
( permalink)
Hi. Do you know how to change new file size from list of files in text file ? Thanks.
|
|
|
|
waitely
-
Total Posts
:
4
- Scores: 0
-
Reward points
:
0
- Joined: 1/31/2011
-
Status: offline
|
Re:VBA script to change some lines in text file.
Wednesday, March 09, 2011 8:31 PM
( permalink)
If you want to edit a specific line in a file through VBScript you can use something like below. This reads the original file line by line and writes it out to a temporary file. If the original line meets the condition you want, make the changes required. At the end, close both files, delete the original and move the temp file. Const ForReading=1 Const ForWriting=2 Set objFSO = CreateObject("Scripting.FileSystemObject") folder = "C:\Program Files\Vendor\" filePath = folder & "file.txt" Set myFile = objFSO.OpenTextFile(filePath, ForReading, True) Set myTemp= objFSO.OpenTextFile(filePath & ".tmp", ForWriting, True) Do While Not myFile.AtEndofStream myLine = myFile.ReadLine If InStr(myLine, "Variable=") Then myLine = "Variable="&whatever End If myTemp.WriteLine myLine Loop myFile.Close myTemp.Close objFSO.DeleteFile(filePath) objFSO.MoveFile filePath&".tmp", filePath Web designers
|
|
|
|