Thread: Read text file
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
shockley shockley is offline
external usenet poster
 
Posts: 135
Default Read text file

You could do something as below using the Input Funciton (not to be confused
with the Input Statement) to read the characters individually and when you
get to a LineFeed, tack on a Carriage Return before it. This procedure
replaces the old file with a new one that has the Carriage Returns inserted.

Sub Tester02()

Open sFile For Input As #1
Do While Not EOF(1)
sChar = Input(1, #1)
If sChar = vbLf Then sChar = vbCr & sChar
sString = sString & sChar
Loop
Close #1

Open sFile For Output As #1
Print #1, sString
Close #1

End Sub

HTH,
Shockley


"jacob" wrote in message
...
Hi,
I'm reading a text file originating from Unix using the
Line Input #Filenumber statement. This goes haywire due
to the fact that each line in the file is terminated with
Chr(10), i.e. linefeed, only. Excel then reads the whole
file into one string as Chr(13) is missing. Anybody know
how to deal with this?
Any help appreciated.

jacob