+ Reply to Thread
Results 1 to 5 of 5

Reading Text Files Into Excel (.Read) and Searching Them

Hybrid View

  1. #1
    Registered User
    Join Date
    07-17-2007
    Posts
    3

    URGENT: Reading Text Files Into Excel (.Read) and Searching Them

    I am trying to read a .txt file (using .Read within VBA):
         filename = "h:\MS1\RccsDiagLog[RCCS_1]Rx26May07033507Rx.txt"
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.OpenTextFile(filename, 1, TristateFalse)
    
        data = f.read(10)
    and get the output formatted and into excel. The problem that I am having is trying to search the file stream for a particular sequence of characters i.e. a double carriage return ( chr(13) & chr(10) & chr(13) ). However, I have no idea how to do this, can anyone help me?

    If this isn't possible I am willing to use another file reading method

    Thanks,

    Mortonic
    Last edited by Mortonic; 07-17-2007 at 08:24 AM. Reason: It has become urgent!

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    There is a simple way that doesn't require any reference and that automatically parses on CR/LF:
    Sub test()
        Filename = "C:\Test.txt"
        Open Filename For Input As #1
       Do While Not EOF(1)
          Input #1, Data1, Data2
        Loop
        Close #1
        MsgBox Data1
        MsgBox Data2
    End Sub
    Best regards,

    Ray

  3. #3
    Registered User
    Join Date
    07-17-2007
    Posts
    3
    Thanks for your help but how do I use that to search for a carriage return followed by a line feed?
    Last edited by Mortonic; 07-18-2007 at 04:40 AM.

  4. #4
    Registered User
    Join Date
    07-17-2007
    Posts
    3
    It's very urgent if anyone at all can help me?

  5. #5
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    This has been tested:
    Sub test()
        Filename = "Retest.txt"
        Open Filename For Input As #1
       Do While Not EOF(1)
          Input #1, Data1
        t = Chr(10) & Chr(10)
        MsgBox InStr(1, Data1, t, vbBinaryCompare)
        Loop
        Close #1
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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