Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2007

Tip: Looking for answers? Try searching our database.

vba filesystemobject EndOfStream EOF

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nicholas Charles - 29 Jan 2007 12:37 GMT
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
Tom Ogilvy - 29 Jan 2007 13:24 GMT
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.

Signature

Regards,
Tom Ogilvy

> Apologies, but new to using INPUT and FileSystemObject
>
[quoted text clipped - 42 lines]
>
> Help, thanks
Nicholas Charles - 29 Jan 2007 13:41 GMT
Tom, many thanks this has helped immensely

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

Regards

Nicholas

> Sub ReadStraightTextFile()
> Dim LineofText As String
[quoted text clipped - 60 lines]
> >
> > Help, thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.