Results 1 to 9 of 9

Using Find() on a text file.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Using Find() on a text file.

    I have a text file of data and I need to remove a subset of the data into excel. For example, I might have a 500 kb file with the specific word "[the_car_color]" and need to extract the word that comes right after it. What's an easy way to do this?

    Some code I've found at http://stackoverflow.com/questions/1...eas-close-file

    Sub ReplaceStringInFile()
    
    Dim sBuf As String
    Dim sTemp As String
    Dim iFileNum As Integer
    Dim sFileName As String
    
    ' Edit as needed
    sFileName = "C:\Temp\test.txt"
    
    iFileNum = FreeFile
    Open sFileName For Input As iFileNum
    
    Do Until EOF(iFileNum)
        Line Input #iFileNum, sBuf
        sTemp = sTemp & sBuf & vbCrLf
    Loop
    Close iFileNum
    
    sTemp = Replace(sTemp, "THIS", "THAT")
    
    iFileNum = FreeFile
    Open sFileName For Output As iFileNum
    Print #iFileNum, sTemp
    Close iFileNum
    
    End Sub
    The above code replaces the text I'm looking for. It doesn't extract it to excel like I need.

    EDIT: I won't needlessly bump this thread since the error was a spelling mistake.
    Last edited by 111StepsAhead; 04-16-2013 at 08:39 AM.

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