Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading a text file line by line


I am looking to bring data into a excel file as a string one line at a
time so I can evaluate the type of data on the line. When I have found
the right data I can brake the string up into the right cells. The line
might have the load case, data type or loads. How do I open the text
file with VBA in Excel and read the file line by line into a string?


--
stressman
------------------------------------------------------------------------
stressman's Profile: http://www.excelforum.com/member.php...o&userid=28139
View this thread: http://www.excelforum.com/showthread...hreadid=476545

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Reading a text file line by line

Try something like the following:

Dim S As String
Open "H:\test.txt" For Input As #1 ' change filename
Do Until EOF(1)
Line Input #1, S
Debug.Print S
Loop
Close #1


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"stressman"
wrote in
message
...

I am looking to bring data into a excel file as a string one
line at a
time so I can evaluate the type of data on the line. When I
have found
the right data I can brake the string up into the right cells.
The line
might have the load case, data type or loads. How do I open
the text
file with VBA in Excel and read the file line by line into a
string?


--
stressman
------------------------------------------------------------------------
stressman's Profile:
http://www.excelforum.com/member.php...o&userid=28139
View this thread:
http://www.excelforum.com/showthread...hreadid=476545



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Reading a text file line by line

i have used this and then modified it to only bring in the line i needed,
but this brings in every line of every .eml file in the folder
it will put it in consecutive lines in column A

Dim ColNdx As Integer
Dim WholeLine As String
Dim FileDir As Variant
Dim FilesInPath As String
Dim MyFiles() As String
Dim NumberOfFiles As Long
Sub import()
Sheets("sheet1").Range("A1").Select
ColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
sRow = RowNdx
FileDir = Environ("USERPROFILE") + "\Desktop\Cats\" ' change this
' determine # of files
FilesInPath = Dir(FileDir & "\*.eml") ' change this location
NumberOfFiles = 0
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

' perform import of email files
Do While FilesInPath < ""
Open FileDir & FilesInPath For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
Cells(RowNdx, ColNdx).Value = WholeLine
RowNdx = RowNdx + 1
Wend
Close #1
' after import, delete unwanted rows
' Range(Rows(sRow), Rows(sRow + 23)).Delete
' Range("A" & sRow).Offset(1, 0).Select
' sRow = sRow + 1
' RowNdx = RowNdx +1
NumberOfFiles = NumberOfFiles + 1

ReDim Preserve MyFiles(1 To NumberOfFiles)
MyFiles(NumberOfFiles) = FilesInPath
FilesInPath = Dir()
Loop
End Sub
--


Gary


"stressman" wrote
in message ...

I am looking to bring data into a excel file as a string one line at a
time so I can evaluate the type of data on the line. When I have found
the right data I can brake the string up into the right cells. The line
might have the load case, data type or loads. How do I open the text
file with VBA in Excel and read the file line by line into a string?


--
stressman
------------------------------------------------------------------------
stressman's Profile:
http://www.excelforum.com/member.php...o&userid=28139
View this thread: http://www.excelforum.com/showthread...hreadid=476545



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading a text file line by line


Thanks that 'Line Input' command done the trick.
I need to get a new book it did not have that command in it.


--
stressman
------------------------------------------------------------------------
stressman's Profile: http://www.excelforum.com/member.php...o&userid=28139
View this thread: http://www.excelforum.com/showthread...hreadid=476545

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Challenge - Excel Line Feed Character CHR(10) - How to Delete and keep the text formatting without going ro single line in a cell ? No Name Excel Worksheet Functions 7 October 7th 09 11:10 AM
Reading a text file line by line Foss[_2_] Excel Programming 4 March 16th 05 04:01 PM
import huge text file line-by-line? rachel Excel Programming 2 November 6th 04 04:43 PM
Reads entire *.txt file into string opposed to a desired line by line input. ej_user Excel Programming 3 October 11th 04 07:15 PM
Excel 2000 Hanging while reading large file with Line Input Jacques Brun Excel Programming 4 February 21st 04 05:05 PM


All times are GMT +1. The time now is 03:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"