Hi Mohan.
You could try reading the lines of the file into an array first.
Then you could access any line at any time.
Dim ReadLine
Dim FN, LineCount As Integer
Dim FileLoc As String
Dim FileArray()
FileLoc = "D:\Transfer\Sample.txt"
FN = FreeFile
LineCount = 0
'First read the lines in the file into an array
Open FileLoc For Input As #FN 'Open file.
Line Input #1, ReadLine 'Get one Line.
LineCount = LineCount + 1 'Increment a counter
ReDim Preserve FileArray(LineCount) 're-dimension the array so that it can add the new line
FileArray(LineCount) = ReadLine 'and add the line to the array
Close #FN
'Now read the array instead of the file and you can move backwards and forwards through the lines
For a = 1 To UBound(FileArray)
Debug.Print FileArray(a) ' Print to the Immediate window.
If a > 1 Then
Debug.Print FileArray(a - 1) ' Prints the previous line to the Immediate window.
End If
If a < UBound(FileArray) Then
Debug.Print FileArray(a + 1) ' Prints the next line to the Immediate window.
End If
Next
Bookmarks