Sub LoadRecipeFile()
Dim ColIndx As Long, I As Long, RowIndx As Long
Dim BatchMarker As String, FormulaList As String, FormulaMarker As String, FormulaType As String
Dim Infile As String, Line As String, PrmName As String, RecipeName As String, TextLine As String
Dim X As Variant
Dim WB As Workbook
Dim WS As Worksheet
BatchMarker = "BATCH_RECIPE NAME="
FormulaMarker = "FORMULA_PARAMETER NAME="
FormulaList = "O_AGIT_ACTIVATE$O_AGIT_MIX_TM$"
Set WB = ActiveWorkbook
X = Application.GetOpenFilename("Text files,*.txt")
If X = "False" Then Exit Sub
Infile = X
WB.Sheets.Add After:=Worksheets(Worksheets.Count)
Set WS = ActiveSheet
With WS
'Header row
.Cells(1, 1).Value = Left(BatchMarker, Len(BatchMarker) - 1)
For I = 0 To UBound(Split(FormulaList, "$"))
.Cells(1, I + 2) = Split(FormulaList, "$")(I)
Next I
Range("A1:C1").Font.Bold = True
With Range("A1:C1").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
WS.Columns.AutoFit
End With
Open Infile For Input Access Read As #1 ' Open text file for read only.
RowIndx = 1
ColIndx = 0
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
Line = Trim(TextLine)
If InStr(Line, BatchMarker) > 0 Then
RowIndx = RowIndx + 1
ColIndx = 0
RecipeName = Split(Line, Chr(34))(1)
End If
If InStr(Line, FormulaMarker) = 1 Then
PrmName = Split(Line, Chr(34))(1) & "$"
If InStr(FormulaList, PrmName) > 0 Then
If ColIndx = 0 Then
ColIndx = ColIndx + 1
Cells(RowIndx, ColIndx) = RecipeName
End If
ColIndx = ColIndx + 1
FormulaType = Split(Line, "=")(UBound(Split(Line, "=")))
If Left(PrmName, Len(PrmName) - 1) <> Cells(1, ColIndx) Then
ColIndx = ColIndx + 1
End If
Cells(RowIndx, ColIndx) = FormulaType
Else
Cells(RowIndx, 1) = RecipeName
End If
End If
Loop
Close #1 ' Close file.
WS.Columns.AutoFit
End Sub