+ Reply to Thread
Results 1 to 9 of 9

FileSystemObject not reading lines

  1. #1
    Registered User
    Join Date
    10-23-2014
    Location
    Raleigh, NC
    MS-Off Ver
    2010
    Posts
    6

    FileSystemObject not reading lines

    Attempting to use FileSystemObject for the first time and running into trouble. I am using the code below on a file (sent to me) and I cannot figure out why it won't work. Seems the AtEndOfStream flag is set to True as soon as the file is read, instead of after all of the lines are processed. Not sure how to handle. Can anyone point me in the right direction? I have attached the sample file as well as the code

    I should mention, I created my own text file and the code worked, so I believe the txt file I received has some issues, but I cannot seem to figure out what the issues are or how to fix them. I did my own searches for ^13 using MS Word and found CR's at the end of every line, however the code below didn't see the individual lines.

    I couldn't find anywhere on the internet that specifically told me what the AtEndOfStream property was looking for (CR, LF, ???) so I am puzzled.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by bimbim9; 10-23-2014 at 04:00 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,365

    Re: FileSystemObject not reading lines

    Your test text file has vbCrLf at the end of each line ... Chr(10) and Chr(13)

    The following code reads the whole text file into a string and then splits the rows into an array using Chr(13). It removes the Chr(10).

    The whole string is output to cell A1; the individual rows are output to cells A2 down.

    Various debug.print statements identify specific characters in the text. You should be able to use this method to identify what characters your data string has.

    Hope this helps:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,365

    Re: FileSystemObject not reading lines

    however the code below didn't see the individual lines.
    Yes it does, at least in the test file. It works just fine. But, if the file isn't structured correctly, who knows.

    Regards, TMS

  4. #4
    Registered User
    Join Date
    10-23-2014
    Location
    Raleigh, NC
    MS-Off Ver
    2010
    Posts
    6

    Re: FileSystemObject not reading lines

    Thanks for your help TMS!
    But, now I am getting Error 62 on this line of code:
    Please Login or Register  to view this content.
    I have confirmed that there are no blanks lines at the end of the file but I don't know what else to do. I can't get the file read into a variable at this point so I am at a loss. Any suggestions would be helpful.

    B

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,365

    Re: FileSystemObject not reading lines

    Can you post a copy of the file you are having problems with?

  6. #6
    Registered User
    Join Date
    10-23-2014
    Location
    Raleigh, NC
    MS-Off Ver
    2010
    Posts
    6

    Re: FileSystemObject not reading lines

    Sure, see attached.
    Attached Files Attached Files

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,365

    Re: FileSystemObject not reading lines

    Is that the file you are having problems with?

  8. #8
    Registered User
    Join Date
    10-23-2014
    Location
    Raleigh, NC
    MS-Off Ver
    2010
    Posts
    6

    Re: FileSystemObject not reading lines

    Sorry for wasting your time, but it looks like the problem was in the filename. Appears I was adding ".txt" to the filename so that the entire file was "test123.txt.txt" while my code was looking for "test123.txt". Thanks again for your assistance.
    B

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,365

    Re: FileSystemObject not reading lines

    Heh, heh, that was the first thing I changed to test.

    I assumed that it was an oversight and that you were actually able to read the file.





    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Reading different lines of data from a textfile into Excel
    By TGM™ in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2013, 09:34 AM
  2. Skip Blank lines when reading a text file
    By parasbshah in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2011, 12:36 PM
  3. Reading Lines from a Textbox
    By Shane O in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2010, 11:24 AM
  4. Reading multiple lines in a VLOOKUP to provide a total?
    By Injury Finger in forum Excel General
    Replies: 4
    Last Post: 03-22-2010, 11:17 AM
  5. Replies: 2
    Last Post: 07-12-2006, 10:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1