Private Sub CreateFile()
'basé sur:FixedFieldTextFile|McGimpsey|231204
Dim NomFic$, FiTxt$, TLgr(), TFmt(), I&, LgrTot&, ZEnreg$, RngColA As Range, Pos&, Lgr&
NomFic = InputBox("Saisir le nom du fichier TXT qui sera exporté dans le répertoire courant.", "Export TXT", ActiveSheet.Name)
FiTxt = ThisWorkbook.Path & "\" & NomFic & ".txt"
TLgr = Array(8, 1, 6, 15, 9, 2, 10, 32, 32, 32, 10, 27, 2, 2, 30, 30, 25, 12, 10, 32, 32, 32, 10, 27, 2, 59)
TFmt = Array("@", "@", "@", "@", "0000", "00", "00", "@", "@", "@", "@", "@", "@", "00", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@")
For I = 0 To UBound(TLgr): LgrTot = LgrTot + TLgr(I): Next I
ZEnreg = String(LgrTot, " ")
Open FiTxt For Output As #1
For Each RngColA In Range("A4:A" & Range("A" & Rows.Count).End(xlUp).Row)
Pos = 1
For I = 0 To UBound(TLgr)
Lgr = TLgr(I)
Mid$(ZEnreg, Pos, Lgr) = Format(RngColA.Offset(0, I).Value, TFmt(I))
Pos = Pos + Lgr: Next I
Print #1, ZEnreg: Next RngColA
Close #1
End Sub