-
I have a text file that I need to replace the 3rd line of data in..
What is the best way to do this?
For example:
I have c:\testfile.txt
It reads:
line 1
line 2
line 3
line 4
I want to change it to read:
line 1
line 2
New line 3
line 4
How can I do that?
Thanks!
-
Code:
Dim iCount As Integer
Dim TmpFile As String
Open "myfile.txt" For Input As #1
Do Until EOF(1)
Line Input #1, tmp
iCount = iCount + 1
If iCount = 3 Then tmp = "NewLineToBePrinted"
TmpFile = TmpFile & tmp & vbCrLf
Loop
Close #1
Open "myfile.txt" For Output As #1
Print #1, TmpFile
Close #1