read a specific line in txt file

User avatar
sal21
PlatinumLounger
Posts: 4402
Joined: 26 Apr 2010, 17:36

read a specific line in txt file

Post by sal21 »

I need to read specific line in a txt file... for eample third line?

User avatar
HansV
Administrator
Posts: 78794
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: read a specific line in txt file

Post by HansV »

Option 1:
Open the text file for input.
Loop from 1 to the specific number, read each line into a variable.
You end up with the desired line.

Option 2:
Open the text file for input.
Read the entire file into a variable.
Use Split with delimiter vbCrLf to create an array of lines.
To get the n-th line, get element n-1 of the array (it starts at 0).
Best wishes,
Hans