Sub ImportTxt()
Dim shDest As Worksheet, i As Long, txtLine As String, tmpVar As Variant
Dim myFso As Object, txtFile As Object
Set shDest = ThisWorkbook.Sheets("Feuil1") 'Feuille dans laquelle seront importer les données
shDest.Cells.Clear
shDest.Cells(1, 1).Value = "id_transaction"
shDest.Cells(1, 2).Value = "appelant"
shDest.Cells(1, 3).Value = "where id"
i = 2
Set myFso = CreateObject("Scripting.FileSystemObject")
Set txtFile = myFso.OpenTextFile("C:\test.txt", 1) 'path du fichier texte
While Not txtFile.AtEndOfStream
txtLine = txtFile.ReadLine
If InStr(txtLine, "id_transaction=""") <> 0 Then
tmpVar = Mid(txtLine, InStr(txtLine, "id_transaction="""), Len(txtLine))
tmpVar = Replace(Replace(tmpVar, "id_transaction=", ""), """", "")
tmpVar = Replace(Replace(tmpVar, vbCr, ""), "\", "")
shDest.Cells(i, 1) = tmpVar
End If
If InStr(txtLine, "&appelant=") <> 0 Then
tmpVar = Mid(txtLine, InStr(txtLine, "&appelant="), Len(txtLine))
tmpVar = Replace(tmpVar, "&appelant=", "")
tmpVar = Replace(Replace(tmpVar, vbCr, ""), "\", "")
If IsNumeric(tmpVar) Then tmpVar = CLng(tmpVar)
shDest.Cells(i, 2) = tmpVar
End If
If InStr(txtLine, "where id=") <> 0 Then
tmpVar = Mid(txtLine, InStr(txtLine, "where id="), Len(txtLine))
tmpVar = Replace(tmpVar, "where id=", "")
tmpVar = Replace(Replace(tmpVar, vbCr, ""), "\", "")
If IsNumeric(tmpVar) Then tmpVar = CLng(tmpVar)
shDest.Cells(i, 3) = tmpVar
End If
If InStr(txtLine, "Fin de transaction") <> 0 Then
i = i + 1
End If
Wend
txtFile.Close
Set txtFile = Nothing: Set myFso = Nothing
End Sub