Exemple :
Prénom : [B]Bernard[/B]
Nom : [B]Tartempion[/B]
adresse : [B]3 rue de l'église[/B]
Bernard;Tartempion; 3 rue de l'église
Polo; 1,8L; 130 chv; Noir
Clim; Auto Radio; jantes; GPS
Sub CreerCSV()
Dim Fichier As String, PrintTxt As String, nB As Byte
nB = FreeFile
Fichier = ActiveWorkbook.Path & "\" & Format(Date, "dd-mm-yyyy") & ".csv"
Open Fichier For Output As nB
PrintTxt = Txt("Clients", 3, nB) 'nom de la feuille, nb de colonne, n° fichier
PrintTxt = Txt("Véhicules", 4, nB)
PrintTxt = Txt("Options", 4, nB)
Close nB
End Sub
Function Txt(ws As String, C As Byte, nB)
Dim i As Long, j As Byte, dl As Long
With Sheets(ws)
dl = .Range("A65000").End(xlUp).Row
For i = 2 To dl
For j = 1 To C
If .Cells(i, j) <> "" Then Txt = Txt & .Cells(i, j) & ";"
Next
If Txt <> "" Then Print #nB, Left(Txt, Len(Txt) - 1)
Txt = ""
Next
End With
End Function
Non, moi c'est kjin...Kjim
nB = FreeFile
PrintTxt = Txt("DEFINITION SOURCE 12-38-39", 16, nB) 'nom de la feuille, nb de colonne, n° fichier
Function Txt(ws As String, C As Byte, nB)
Dim i As Long, j As Byte, dl As Long
With Sheets(ws)
dl = .Range("A65000").End(xlUp).Row
For i = 5 To dl
For j = 1 To C
If .Cells(i, j) <> "" Then Txt = Txt & .Cells(i, j) & ";"
Next
If Txt <> "" Then Print #nB, Left(Txt, Len(Txt) - 1)
Txt = ""
Next
End With
End Function
FreeFile, fonction, exemple
Cet exemple utilise la fonction FreeFile pour renvoyer le prochain numéro de fichier disponible. Cinq fichiers sont ouverts à l'intérieur de la boucle et des données sont écrites dans chacun d'eux.
Dim MyIndex, FileNumber
For MyIndex = 1 To 5 ' La boucle est effectuée cinq fois.
FileNumber = FreeFile ' Lit le numéro de fichier inutilisé.
' Crée le nom du fichier.
Open "TEST" & MyIndex For Output As #FileNumber
Write #FileNumber, "Ceci est un exemple" ' Écrit le texte.
Close #FileNumber ' Ferme le fichier.
Next MyIndex
Fichier = ActiveWorkbook.Path & "\" & Range("B5").Value & "-" & Range("E5").Value & "-" & Format(Date, "dd-mm-yyyy") & ".csv"
Pas très clair tout ça...Mais mon bouton "Creat CSV" est sur plusieurs Feuilles.
Donc j'aimerai remplacer ce ActiveWorkbook par Feuille1 (pour mettre le chemin en dur) mais je ne trouve pas la bonne syntaxe :s
ActiveWorkbook.Path & "\
Par ailleurs tu dis avoir plusieurs boutons;faut-il utiliser dans tout les cas "Feuil1" pour le répertoire ou le nom de la feuille où se situe le bouton ?
kjin
With Sheets("[COLOR="Blue"]Feuille1[/COLOR]")
Fichier = ActiveWorkbook.Path & "\" & .Range("B5") & "-" & .Range("E5") & "-" & Format(Date, "dd-mm-yyyy") & ".csv"
End With