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
| 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: 'signifie que l'importation des données se fera en cellule B2
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()
End Sub
Private Sub importer_Click()
Dim fichier_choisi As String
fichier_choisi = Application.GetOpenFilename("Text Files (*.txt),*.txt", , "Selectionner un fichier CSV")
If (LCase(fichier_choisi) <> "faux" And fichier_choisi <> "0") Then
liste_fichiers.AddItem (fichier_choisi)
End If
End Sub
Private Sub UserForm_Click()
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 |
Partager