Je donne un exemple de code qui n'a pas marché:
Sub Search_and_Copy()
Dim inputFileName As String, outputFileName As String
Dim startText As String, endText As String
Dim FSO As Object
Dim textFile As Object
Dim data As String
Dim p1 As Long, p2 As Long
inputFileName = "C:\5_4_2012\123.txt" 'INPUT FILE - CHANGE AS REQUIRED
outputFileName = "C:\5_4_2012\text2.txt" 'OUTPUT FILE - CHANGE AS REQUIRED
startText = "FLIGHT"
endText = "End"
Set FSO = CreateObject("Scripting.FileSystemObject" )
Set textFile = FSO.OpenTextFile(inputFileName)
data = textFile.ReadAll
textFile.Close
p1 = InStr(data, startText)
If p1 > 0 Then
p1 = InStr(p1, data, vbCrLf)
If p1 > 0 Then
p1 = p1 + 2
p2 = InStr(p1, data, endText)
If p2 > 0 Then
p2 = InStrRev(data, vbCrLf, p2)
Set textFile = FSO.CreateTextFile(outputFileName)
textFile.Write Mid(data, p1, p2 - p1)
textFile.Close
End If
End If
End If
End Sub
Je ne sais pas prquoi ça n'a pas fonctionné, bien qu'il me donne ni message d'erreur, ni un arret de la procédure!!!!