vba help - Read Text file two line one go

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
983
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

In a text file can we Read both line one go. in excel we have offset Option.
Read both line and take Action.


If InStr(strline, "Rejected") > 0 And InStr(Nextline, "Error") > 0 Then

end if

Sub test()

Dim fso As Scripting.FileSystemObject
Dim tsTxtFile As Scripting.TextStream
Dim strline As String

Set fso = New Scripting.FileSystemObject
Set tsTxtFile = fso.OpenTextFile("C:\test\test.txt", ForReading, False, TristateMixed)

With tsTxtFile

Do Until .AtEndOfStream

strline = tsTxtFile.ReadLine

If InStr(strline, "Rejected") > 0 And InStr(Nextline, "Error") > 0 Then ' Nextline is offset


End If

Loop


Thanks
mg
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I don't use the Scripting.FileSystemObject myself, but given has a ReadLine method, can't you just add this...

Nextline = tsTxtFile.ReadLine

immediately after this line...

strline = tsTxtFile.ReadLine

inside your loop?
 
Upvote 0
Hi Rick,

through loop we can do it.

But Reading two lines in one go option not available.
skip option is there but it skips next line instead of existing line.



Thanks
mg
 
Upvote 0
Did what I suggested not work for you (it should read two lines for each loop)?
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top