Y
yorrick
Guest
bonjour,
J'utilise la macro suivante :
Private Sub CommandButton1_Click()
Dim Lig, Col, x0, x1 As Long
Dim b0, b1, b2, d, dv As String
Dim Fic, adxirs, adxifs As String
Fic = 'C:\\tft cde excel\\nomdufichier.txt'
d = Chr$(34)
dv = d + ';'
Sheets('Feuil1').Activate
Range('A1').Activate
Open Fic For Output As #1
b0 = ''
x0 = 0
Lig = 1
Do While ActiveCell.Offset(Lig, 0).Text <> ''
b1 = ActiveCell.Offset(Lig, 0).Text
x0 = x0 + 1
If x0 = 185 Then
x0 = 0
b0 = ''
End If
If b0 <> b1 Then
'---- nouvelle commande
Print #1, d & 'E' & dv;
Print #1, d & ActiveCell.Offset(Lig, 0).Text & dv;
Print #1, d & ActiveCell.Offset(Lig, 2).Text & dv;
Print #1, d & ActiveCell.Offset(Lig, 1).Text & d
b0 = b1
End If
Print #1, d & 'L' & dv;
Print #1, d & ActiveCell.Offset(Lig, 3).Text & dv;
Print #1, d & ActiveCell.Offset(Lig, 4).Text & d
Lig = Lig + 1
Loop
Close #1
MsgBox ('Fichier ' & Fic & ' généré !')
End Sub
J'aimerais pouvoir faire en sorte que le nom du fichier txt
soit demandé par une fenetre dans le fichier exce lors du lancement de la macro.
Ou si cela n'est pas possible le contenu d'une cellule de ma
feuille excel.
Merci d'avance de votre aide.
J'utilise la macro suivante :
Private Sub CommandButton1_Click()
Dim Lig, Col, x0, x1 As Long
Dim b0, b1, b2, d, dv As String
Dim Fic, adxirs, adxifs As String
Fic = 'C:\\tft cde excel\\nomdufichier.txt'
d = Chr$(34)
dv = d + ';'
Sheets('Feuil1').Activate
Range('A1').Activate
Open Fic For Output As #1
b0 = ''
x0 = 0
Lig = 1
Do While ActiveCell.Offset(Lig, 0).Text <> ''
b1 = ActiveCell.Offset(Lig, 0).Text
x0 = x0 + 1
If x0 = 185 Then
x0 = 0
b0 = ''
End If
If b0 <> b1 Then
'---- nouvelle commande
Print #1, d & 'E' & dv;
Print #1, d & ActiveCell.Offset(Lig, 0).Text & dv;
Print #1, d & ActiveCell.Offset(Lig, 2).Text & dv;
Print #1, d & ActiveCell.Offset(Lig, 1).Text & d
b0 = b1
End If
Print #1, d & 'L' & dv;
Print #1, d & ActiveCell.Offset(Lig, 3).Text & dv;
Print #1, d & ActiveCell.Offset(Lig, 4).Text & d
Lig = Lig + 1
Loop
Close #1
MsgBox ('Fichier ' & Fic & ' généré !')
End Sub
J'aimerais pouvoir faire en sorte que le nom du fichier txt
soit demandé par une fenetre dans le fichier exce lors du lancement de la macro.
Ou si cela n'est pas possible le contenu d'une cellule de ma
feuille excel.
Merci d'avance de votre aide.