Enregistrement en csv par VBA pour export SAP

Résolu/Fermé
Dubi21 Messages postés 48 Date d'inscription samedi 25 janvier 2014 Statut Membre Dernière intervention 25 octobre 2016 - 12 déc. 2015 à 18:01
Dubi21 Messages postés 48 Date d'inscription samedi 25 janvier 2014 Statut Membre Dernière intervention 25 octobre 2016 - 15 déc. 2015 à 09:14
Bonjour,

Je rencontre un problème au niveau du format de mon fichier excel pour exporter sur SAP avec une sauvegarde CSV par ma programmation vba.

Donc j'ai mon code VBA qui enregistre en csv, le format semble correct (même visuel qu'un enregistrement manuelle en csv) mais lorsque je l'importe sur SAP, ça ma met que le format n'est pas correct. La seul chose qui change c'est la poids du fichiers 1.91ko pour ma sauvegarde vba et 1.88ko pour une sauvegarde manuelle.

J'ai intégré un code de ce type pour mon enregistrement CSV
Sub SaveAsCSV()
Dim Range As Object, Line As Object, Cell As Object
Dim StrTemp, chemin As String

Dim Separateur As String
chemin = ThisWorkbook.Path & ""
Separateur = ";"
Set Range = ActiveSheet.UsedRange

Open chemin & nom2 & ".csv" For Output As #1
For Each Line In Range.Rows
StrTemp = ""
For Each Cell In Line.Cells
StrTemp = StrTemp & CStr _
(Cell.Text) & Separateur
Next
Print #1, StrTemp '= " "
Next
Close
End Sub

Auriez vous une idée d’où pourrait provenir mon problème?

merci

2 réponses

Bonjour

Voila un macro qui fait des CSV regarde bien ?
Sub ExportCSV()
Application.ScreenUpdating = False
Nom = "Test"
Ext = ".csv"
Fichier = Nom & Ext
Chemin = ActiveWorkbook.Path & Application.PathSeparator
CheminFiche = Chemin & Fichier
Sep = ";"
Nlig = Cells(Rows.Count, 1).End(xlUp).Row
   Set Plage = Range("A1:E" & Nlig)
      Open CheminFiche For Output As #1
         For Each Lig In Plage.Rows
            ligne = ""
               For Each Cel In Lig.Cells
                  ligne = ligne & CStr(Cel.Text) & Sep
               Next
            Print #1, ligne
         Next
      Close
   Set Plage = Nothing
Application.ScreenUpdating = True
MsgBox "Terminer"
End Sub

A+
Maurice
0
Dubi21 Messages postés 48 Date d'inscription samedi 25 janvier 2014 Statut Membre Dernière intervention 25 octobre 2016
Modifié par Dubi21 le 13/12/2015 à 10:25
J'essaye ça dès lundi merci beaucoup donc normalement ça me donne exactement le même enregistrement qu'en le faisant manuellement
0
Dubi21 Messages postés 48 Date d'inscription samedi 25 janvier 2014 Statut Membre Dernière intervention 25 octobre 2016 > Dubi21 Messages postés 48 Date d'inscription samedi 25 janvier 2014 Statut Membre Dernière intervention 25 octobre 2016
14 déc. 2015 à 14:19
J'ai intégré ta macro à mon fichier en complétant pour définir (nom, ext,...) donc cela fonctionne bien même visuelle que si je l'enregistre manuellement mais je me retrouve avec le même problème que ma macro. Problème de format quand je l'importe sur SAP. Je ne sais pas d'où provient cette petite différence de l'enregistrement macro et enregistrement manuel...
0
Bonjour

alors peux être comme ça

Sub ExportCSV()
Application.ScreenUpdating = False
Nom = "Test"
Ext = ".csv"
Fichier = Nom & Ext
Chemin = ActiveWorkbook.Path & Application.PathSeparator
CheminFiche = Chemin & Fichier
Sep = ";"
Nlig = Cells(Rows.Count, 1).End(xlUp).Row
   Set Plage = Range("A1:E" & Nlig)
      Open CheminFiche For Output As #1
         For Each Lig In Plage.Rows
            ligne = ""
               For Each Cel In Lig.Cells
                  ligne = ligne & CStr(Cel.Text) & Sep
               Next
             Print #1, Left(ligne, Len(ligne) - 1)
         Next
      Close
   Set Plage = Nothing
Application.ScreenUpdating = True
MsgBox "Terminer"
End Sub


Voir la Ligne Print #1, Left(ligne, Len(ligne) - 1)
après je ne sait plus car j'ais pas de SAP
A+
Maurice
0
Dubi21 Messages postés 48 Date d'inscription samedi 25 janvier 2014 Statut Membre Dernière intervention 25 octobre 2016
15 déc. 2015 à 09:14
Merci Maurice pour ton aide, le problème venait de la plage de sélection, il fallait que je prenne juste le bon nombre de colonne, j'étais un peu trop large.
Merci à toi ^^
0