Oki doki, voici donc le code... En fait, comme je l'ai expliqué, tout se passe comme je le souhaite tant que je ne fais pas autre chose (ie que je laisse la fenêtre d'Excel active).
Private Sub Commandbutton1_Click()
chemin = Sheets("feuil1").Range("J3").Formula
fichier = chemin & "Work\temp.txt"
test = True
i = 3
While test
If Sheets("feuil1").Range("G" & i).Formula <> "" Then
Sheets("feuil1").Range("A" & i).Formula = ""
Sheets("feuil1").Range("A" & i + 1).Formula = ""
Sheets("feuil1").Range("B" & i).Formula = ""
Sheets("feuil1").Range("C" & i).Formula = ""
Sheets("feuil1").Range("D" & i).Formula = ""
Sheets("feuil1").Range("E" & i).Formula = ""
Sheets("feuil1").Range("F" & i).Formula = ""
Sheets("feuil1").Range("G" & i).Formula = ""
i = i + 1
Else
test = False
End If
Wend
Sheets("feuil1").Range("J10").Formula = ""
Sheets("feuil1").Range("J11").Formula = ""
fin = Timer
While Dir(fichier) = ""
Wend
k = 3
C_old = 0
eps1max_old = 0
eps1maxaxe_old = 0
angle_old = 0
While Dir(chemin & "Work\file.bat") <> ""
Open fichier For Input As #1
While Not EOF(1)
Line Input #1, Texte
If Mid(Texte, 1, 14) = "*SET,C ," Then
C = Val(Mid(Texte, 16, 20))
End If
If Mid(Texte, 1, 15) = "*SET,EPS_1_MAX," Then
eps1max = Val(Mid(Texte, 18, 20))
End If
If Mid(Texte, 1, 19) = "*SET,EPS_1_MAX_AXE," Then
eps1maxaxe = Val(Mid(Texte, 21, 20))
End If
If Mid(Texte, 1, 10) = "*SET,ANGLE" Then
Angle = Val(Mid(Texte, 17, 20))
End If
If Mid(Texte, 1, 10) = "*SET,N_PAS" Then
n_pas = Val(Mid(Texte, 17, 20))
End If
If Mid(Texte, 1, 14) = "*SET,PAS ," Then
pas = Val(Mid(Texte, 17, 20))
End If
Wend
Close #1
If C <> C_old Then
debut = fin
fin = Timer
Sheets("feuil1").Range("A" & k + 1).Value = Angle
Sheets("feuil1").Range("B" & k).Value = pas
Sheets("feuil1").Range("C" & k).Value = C
Sheets("feuil1").Range("D" & k).Value = eps1max
Sheets("feuil1").Range("E" & k).Value = eps1maxaxe
If n_pas = 999999 Then
Sheets("feuil1").Range("F" & k).Formula = "Planté !"
End If
Sheets("feuil1").Range("G" & k).Value = fin - debut
k = k + 1
End If
C_old = C
Wend
debut = fin
fin = Timer
Sheets("feuil1").Range("G" & k).Value = fin - debut
test = True
debut = Timer
While test
fin = Timer
If fin - debut > 5 Then
test = False
End If
Wend
Open chemin & "Output\result.txt" For Input As #1
Line Input #1, Texte
For i = 1 To Len(Texte)
If Mid(Texte, i, 6) = "N.m/mm" Then
Texte2 = Mid(Texte, i - 10, 8)
Sheets("feuil1").Range("J11").Formula = Texte2
End If
If Mid(Texte, i, 1) = ":" Then
Texte3 = Mid(Texte, 1, i - 2)
Sheets("feuil1").Range("J10").Formula = Texte3
End If
Next i
Close #1
End Sub