Try this simple parser. It searches for the sequence HATCH - 5 - A7123 - 62. If that exact sequence is found it displays the line after 62 and resets the search to find the next sequence. If any of those strings are found out of sequence it resets the search to the beginning of the sequence (HATCH).
To modify the file contents, open a second file for output, read from the input file and write to the output file, modifying the found line (1 in your example) with the Excel cell value. At the end delete the original file using Kill and rename the second file using Name.
Code:Public Sub Parsedxf() Dim sFileName As String Dim iFileNum As Integer Dim Fields As String Dim nextField As String sFileName = "E:\Batch\parse.txt" iFileNum = FreeFile() Open sFileName For Input As iFileNum nextField = "HATCH" Do While Not EOF(iFileNum) Line Input #iFileNum, Fields Debug.Print Fields, nextField If Fields = "HATCH" Then If nextField = "HATCH" Then nextField = "5" End If ElseIf Fields = "5" Then If nextField = "5" Then nextField = "A7123" Else nextField = "HATCH" End If ElseIf Fields = "A7123" Then If nextField = "A7123" Then nextField = "62" Else nextField = "HATCH" End If ElseIf Fields = "62" Then If nextField = "62" Then nextField = "NEXT LINE" Else nextField = "HATCH" End If ElseIf nextField = "NEXT LINE" Then MsgBox Fields 'display required line nextField = "HATCH" 'reset search End If Loop Close iFileNum End Sub


LinkBack URL
About LinkBacks



Reply With Quote


Bookmarks