Exporter vers fichier text en forcant le format date et nomb

Bonjour,

J'ai une macro excel qui écrit dans un fichier texte. Voici le bout qui écrit:

For i = 1 To derniereligne

Print #1, Format(ActiveSheet.Cells(i, 1).Value, "dd/mm/yyyy"); ";"; _

ActiveSheet.Cells(i, 2).Value; ";"; _

ActiveSheet.Cells(i, 3).Value; ";"; Format(ActiveSheet.Cells(i, 4).Value, "0.0000"); _

";"; Format(ActiveSheet.Cells(i, 5).Value, "0.00")

Next

J'ai ajouté une commande format pour conserver le format apparent dans excel mais ca ne marche pas.

Dans excel j'ai des dates dans la premiére colonne au format dd/mm/yyyy mais dans le texte ils deviennent dd.mm.yyyy

Pour les nombres le format apparent est avec , comme séparateur de décimale mais je souhaiterais un point. Ma commande format ne produit pas non plus de bon résultat dans ce cas-lá

Je précise que j'ai essayé la commande suivante

valeur = Replace(ActiveSheet.Cells(i, 5).Value, ",", ".")

ca permet bien d'écrire un point á la place de la virgule mais en revanche, ca ne maintient pas les deux décimales.

Fabien

Résolu avec un code peu élégant qui exporte, importe puis reexeporte le texte:

Private Sub Export_Citrix_Click()
Dim derniereligne As Integer, i As Integer
Dim j As Integer

Sheets("Export Citrix").Select
derniereligne = ActiveSheet.Range("F51").Value

Open "c:/export_citrix.csv" For Output As 1

For i = 1 To derniereligne
    Print #1, Format(ActiveSheet.Cells(i, 1).Value, "dd/mm/yyyy"); ";"; _
    ActiveSheet.Cells(i, 2).Value; ";"; _
    ActiveSheet.Cells(i, 3).Value; ";"; Format(ActiveSheet.Cells(i, 4).Value, "0.0000"); _
    ";"; Format(ActiveSheet.Cells(i, 5).Value, "0.00")
Next

Close

Open "c:/export_citrix.csv" For Input As 1
i = 1
While Not EOF(1)
    Line Input #1, a
    'Copie des lignes dans excel
    ActiveSheet.Cells(i, 8).Value = a
    i = i + 1
Wend
Close

ActiveSheet.Columns("H:L").Select
Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
Selection.Replace What:=",", Replacement:=".", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

Open "c:/export_citrix.csv" For Output As 1
For i = 1 To derniereligne
    'valeur = Replace(ActiveSheet.Cells(i, 5).Value, ",", ".")
    Print #1, ActiveSheet.Cells(i, 8).Value
Next
Close

End Sub

Fabien

Rechercher des sujets similaires à "exporter fichier text forcant format date nomb"