Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba filesystemobject EndOfStream EOF

Apologies, but new to using INPUT and FileSystemObject

when i reference a MSword (.doc) file and/or some text (.txt) files using
INPUT or File System Object, it opens the whole contents as one string ie no
line feeds to seperate each row. how can i loop through each row ?

is this an issue to do with a linefeed break at end of each row ? or can
the text be split but some meansd of a charactor count and adding a line feed
first, then

Dim objFSO As FileSystemObject
Dim t As TextStream

Dim vEachLine
Dim sTempStr

Set objFSO = New FileSystemObject
Set t = objFSO.OpenTextFile(sFile, 1, False)

' does not like next line ?? (i found this code in a colleagues workbook)
vEachLine = Split(objFSO.OpenTextFile(sFile).ReadAll, vbCrLf)

' and if i use
While Not t.AtEndOfStream
Debug.Print ts.ReadLine
Wend

each 'line' is the tewxt in the whole document ?

the INPUT method ive also tried adapting is
hFile = FreeFile
Open sFILE For Input As #hFile

i = 0
j = 2
Do While Not EOF(hFile)
' code here
Loop


'close file
Close #hFile

' but this still as all contents in one string ??

Help, thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default vba filesystemobject EndOfStream EOF

Sub ReadStraightTextFile()
Dim LineofText As String
Dim rw as Long
rw = 0
Open "C:\FILEIO\TEXTFILE.TXT" For Input As #1
Do While Not EOF(1)
Line Input #1, LineofText
rw = rw + 1
cells(rw,1).Value = LineofText
Loop
'Close the file
Close #1
End Sub


A MSWord doc file is a binary file and you will not get any meaningful input
from reading a DOC file. The above should work with a normal windows text
file.

--
Regards,
Tom Ogilvy


"Nicholas Charles" wrote:

Apologies, but new to using INPUT and FileSystemObject

when i reference a MSword (.doc) file and/or some text (.txt) files using
INPUT or File System Object, it opens the whole contents as one string ie no
line feeds to seperate each row. how can i loop through each row ?

is this an issue to do with a linefeed break at end of each row ? or can
the text be split but some meansd of a charactor count and adding a line feed
first, then

Dim objFSO As FileSystemObject
Dim t As TextStream

Dim vEachLine
Dim sTempStr

Set objFSO = New FileSystemObject
Set t = objFSO.OpenTextFile(sFile, 1, False)

' does not like next line ?? (i found this code in a colleagues workbook)
vEachLine = Split(objFSO.OpenTextFile(sFile).ReadAll, vbCrLf)

' and if i use
While Not t.AtEndOfStream
Debug.Print ts.ReadLine
Wend

each 'line' is the tewxt in the whole document ?

the INPUT method ive also tried adapting is
hFile = FreeFile
Open sFILE For Input As #hFile

i = 0
j = 2
Do While Not EOF(hFile)
' code here
Loop


'close file
Close #hFile

' but this still as all contents in one string ??

Help, thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba filesystemobject EndOfStream EOF

Tom, many thanks this has helped immensely

I thought it was something like that, re .doc file / txt file.

Regards

Nicholas

"Tom Ogilvy" wrote:

Sub ReadStraightTextFile()
Dim LineofText As String
Dim rw as Long
rw = 0
Open "C:\FILEIO\TEXTFILE.TXT" For Input As #1
Do While Not EOF(1)
Line Input #1, LineofText
rw = rw + 1
cells(rw,1).Value = LineofText
Loop
'Close the file
Close #1
End Sub


A MSWord doc file is a binary file and you will not get any meaningful input
from reading a DOC file. The above should work with a normal windows text
file.

--
Regards,
Tom Ogilvy


"Nicholas Charles" wrote:

Apologies, but new to using INPUT and FileSystemObject

when i reference a MSword (.doc) file and/or some text (.txt) files using
INPUT or File System Object, it opens the whole contents as one string ie no
line feeds to seperate each row. how can i loop through each row ?

is this an issue to do with a linefeed break at end of each row ? or can
the text be split but some meansd of a charactor count and adding a line feed
first, then

Dim objFSO As FileSystemObject
Dim t As TextStream

Dim vEachLine
Dim sTempStr

Set objFSO = New FileSystemObject
Set t = objFSO.OpenTextFile(sFile, 1, False)

' does not like next line ?? (i found this code in a colleagues workbook)
vEachLine = Split(objFSO.OpenTextFile(sFile).ReadAll, vbCrLf)

' and if i use
While Not t.AtEndOfStream
Debug.Print ts.ReadLine
Wend

each 'line' is the tewxt in the whole document ?

the INPUT method ive also tried adapting is
hFile = FreeFile
Open sFILE For Input As #hFile

i = 0
j = 2
Do While Not EOF(hFile)
' code here
Loop


'close file
Close #hFile

' but this still as all contents in one string ??

Help, thanks

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
FileSystemObject help please. Tom Ogilvy Excel Programming 0 July 8th 05 04:44 PM
Filesystemobject Help CyndyG Excel Programming 4 May 17th 05 01:00 AM
filesystemobject Alvin Hansen[_2_] Excel Programming 2 February 16th 05 03:47 PM
filesystemobject Alvin Hansen[_2_] Excel Programming 3 January 27th 05 06:17 PM
FileSystemObject lol[_2_] Excel Programming 2 April 6th 04 09:56 PM


All times are GMT +1. The time now is 04:25 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"