How To Offset a specific Number of Rows in a Text File

R

R Tanner

Hi,

I have a macro that is going through and evaluating each line of a
text file and importing it if it meets specific criteria. I need to
skip a certain number of rows if a certain criteria is met. What
syntax would I use to skip down a certain number of lines? This is
how I have been opening the file thus far.

FileNum=FreeFile

FileName = "Q:\Operations\Feedback Scores.LOG"

Open FileName For Input Lock Write as FileNum
 
G

GP

I wouldn't use the "Open File For" method.

If you add a reference to Microsoft Scripting Runtime (Tools, References)
you get access to the TextStream object. You can use it like this:

Dim myFileSytem as Scripting.FileSystemObject
Dim myStream as TextStream
Dim myLine as String
Set myFileSytem = CreateObject("Scripting.FileSystemObject")
Set myStream = myFileSytem.OpenTextFile("C:\text.ini") 'or whatever path
While myStream.AtEndOfStream = False
myLine = myStream.ReadLine
'code here
Wend
myStream.Close

This reads through the text file line by line. To ignore soem lines you just
put code in the While...Wend loop that reads those lines but takes no action..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top