Bonsoir,

Je suis novice en VBA, j'ai un fichier .csv que je voudrais exporter dans ma boutique shopify pour mettre à jour mes produits, le soucis c'est que dans shopify la structure est en html de mes champs.

Avez vous une idée ?

voici mon bout de code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 
Dim ligne_debut As Integer: Dim colonne_debut As Integer
 
Dim ligne_fin As Integer: Dim colonne_fin As Integer
 
Dim ligne_enCours As Integer: Dim colonne_enCours As Integer
 
Private Sub exporter_Click()
Dim nom_fichier As String
 
ligne_debut = 2: colonne_debut = 2
ligne_enCours = ligne_debut: colonne_enCours = colonne_debut
 
Cells.Clear
 
For i = 0 To liste_fichiers.ListCount - 1
    lecture (liste_fichiers.List(i))
Next i
 
traitement
nom_fichier = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
sortie.Value = nom_fichier
ecriture (nom_fichier)
 
End Sub
 
Private Sub fermer_Click()
liste_fichiers.Clear
formulaire.Hide
End Sub
 
Private Sub importer_Click()
Dim fichier_choisi As String
 
fichier_choisi = Application.GetOpenFilename("Text Files(*.txt), *.txt", , "Sélectionner le fichier CSV")
If (LCase(fichier_choisi) <> "faux" And fichier_choisi <> "0") Then
    liste_fichiers.AddItem (fichier_choisi)
End If
 
End Sub
 
Private Sub lecture(fichier As String)
Dim depart As Integer, position As Integer
Dim texte As String, tampon As String
 
Open fichier For Input As #1
 
Do While Not EOF(1)
 
    Line Input #1, texte
    depart = 1: position = 1
    Do While (position <> 0)
 
    position = InStr(depart, texte, ";", 1)
    If position = 0 Then
        tampon = Mid(texte, depart)
        Sheets("Import").Cells(ligne_enCours, colonne_enCours).Value = tampon
        Exit Do
        Else
            tampon = Mid(texte, depart, position - depart)
    End If
 
    Sheets("Import").Cells(ligne_enCours, colonne_enCours).Value = tampon
    depart = position + 1
    colonne_enCours = colonne_enCours + 1
    Loop
 
    colonne_enCours = colonne_debut
    ligne_enCours = ligne_enCours + 1
 
Loop
 
Close #1
 
End Sub
 
Private Sub ecriture(fichier As String)
Dim ligne As Integer, colonne As Integer
Dim texte As String
ligne = ligne_debut: colonne = colonne_debut
 
If LCase(fichier) <> "faux" Then
 
Open fichier For Output As #1
   While Cells(ligne, colonne).Value <> ""
    While Cells(ligne, colonne).Value <> ""
        texte = texte & Cells(ligne, colonne).Value & ";"
        colonne = colonne + 1
    Wend
        Print #1, texte
        texte = ""
        colonne = colonne_debut
        ligne = ligne + 1
   Wend
 
Close #1
 
End If
End Sub
 
Private Sub traitement()
Dim ligne As Integer: Dim colonne As Integer
ligne = ligne_debut: colonne = colonne_debut
 
Cells(ligne, colonne).Sort Cells(ligne, colonne), xlAscending, Header:=xlNo
 
While Cells(ligne, colonne).Value <> ""
 
    If (Cells(ligne, colonne).Value = Cells(ligne - 1, colonne).Value) Then
        Cells(ligne, colonne).EntireRow.Delete
        ligne = ligne - 1
    End If
    ligne = ligne + 1
Wend
 
End Sub
 
Private Sub UserForm_Click()
 
End Sub