Code:'search for a particular line and do something with it 'read the file into an array 'find the line you are looking for ' then read the array back into the file using Output 'so you can overwrite the original file Option Explicit Option Compare Text Private Sub Form_Load() Dim myArr() As Variant, myLine As String Dim myComp As String Dim i As Integer, intNum As Integer myComp = "The line I am Looking for" intNum = FreeFile ' 'open file Open "C:\myfile.txt" For Input As intNum Do While Not EOF(intNum) i = i + 1 ReDim Preserve myArr(1 To i) As Variant Line Input #intNum, myLine myArr(i) = myLine myArr(i) = Trim(myArr(i)) If myArr(i) = myComp Then 'do whatever you want to here I change it to read "My Fixed Line" myArr(i) = "My Fixed Line" End If Loop Close #intNum 'open file and save new contents Open "c:\myfile.txt" For Output As intNum For i = 1 To UBound(myArr) Print #intNum, myArr(i) Next Close #intNum End Sub




Reply With Quote