Actually, you can do this with 15 lines of code and process only one line at a time to eliminate any memory concerns. I've added comments to explain it as it goes.
Code:Dim InputFileNum As Integer Dim OutputFileNum As Integer Dim Buffer As String ' Get the input file handle and open for input-only InputFileNum = FreeFile Open "SourceFile.txt" For Input As InputFileNum ' Get the output file handle and open/create the file OutputFileNum = FreeFile Open "OutputFile.txt" For Output As OutputFileNum ' Read each line in the input file one line at a time While Not EOF(InputFileNum) ' Reads one line of text Line Input #InputFileNum, Buffer ' Check to see if MAMPLASAN is contained in that line...this is NOT case sensitive ' Use vbBinaryCompare if you are looking for case sensitive If (InStr(1, Buffer, "MAMPLASAN", vbTextCompare) <> 0) Then ' If it is found, output it to the destination file Print #OutputFileNum, Buffer End If Wend Close #OutputFileNum Close #InputFileNum




Reply With Quote