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.
Bookmarks