Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the following code and it works as is but I would like the code to
start reading at line three of the text file. Is that possible and if so, how? Public Sub GetIt() Set fs = CreateObject("Scripting.FileSystemObject") Dim r As Integer Set ImpRng = ActiveCell strFile = Application.GetOpenFilename strFile = fs.GetFileName(strFile) Open strFile For Input As #1 r = 0 Do While Not EOF(1) 'Want to start at line three of text file Line Input #1, data ActiveCell.Offset(r, 0) = LTrim(data) r = r + 1 Loop Close #1 End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you text is managable (<~ 5MB), you get the whole file in one go. Also
the FSO is slow and provides no functionality the VBA does not natively have. Dim AllFile() As String Dim FileNum As Long Dim i As Long FileNum = FreeFile Open ThisWorkbook.Path & "\Book2.csv" For Input As #FileNum AllFile = Split(Input(LOF(FileNum), FileNum), vbNewLine) Close #FileNum For i = LBound(AllFile) + 2 To UBound(AllFile) 'Do something Debug.Print AllFile(i) Next NickHK "Billy B" wrote in message ... I have the following code and it works as is but I would like the code to start reading at line three of the text file. Is that possible and if so, how? Public Sub GetIt() Set fs = CreateObject("Scripting.FileSystemObject") Dim r As Integer Set ImpRng = ActiveCell strFile = Application.GetOpenFilename strFile = fs.GetFileName(strFile) Open strFile For Input As #1 r = 0 Do While Not EOF(1) 'Want to start at line three of text file Line Input #1, data ActiveCell.Offset(r, 0) = LTrim(data) r = r + 1 Loop Close #1 End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Billy
The SkipLine method from the fileSystemObject is one way: strFile = Application.GetOpenFilename strFileToRead = fs.OpenTextFile(strFile,ForReading) For i = 1 to 2 strFileToRead.SkipLine Next i strFileToRead.ReadLine .... HTH Cordially Pascal "Billy B" a écrit dans le message de news: ... I have the following code and it works as is but I would like the code to start reading at line three of the text file. Is that possible and if so, how? Public Sub GetIt() Set fs = CreateObject("Scripting.FileSystemObject") Dim r As Integer Set ImpRng = ActiveCell strFile = Application.GetOpenFilename strFile = fs.GetFileName(strFile) Open strFile For Input As #1 r = 0 Do While Not EOF(1) 'Want to start at line three of text file Line Input #1, data ActiveCell.Offset(r, 0) = LTrim(data) r = r + 1 Loop Close #1 End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Reading a text file line by line | Excel Programming | |||
Reading a text file line by line | Excel Programming | |||
Trying to start a second line ( ie use of enter key) in an output file | Excel Programming | |||
Excel 2000 Hanging while reading large file with Line Input | Excel Programming |