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
| Sub Import_Fichier()
' importe des fichiers texte en ouvrant une fenêtre
Dim file As FileDialog
Dim strLigne As String
Dim str() As String
Dim i As Integer
Dim Ligne As Long
'Choix du fichier à importer
Set file = Application.FileDialog(msoFileDialogFilePicker)
file.Filters.Clear
file.Filters.Add "Fichier CSV", "*.csv"
file.Title = "Fichier à importer"
If file.Show = False Then
Exit Sub
End If
Ligne = 2
'Ouverture du fichier
Open file.SelectedItems(1) For Input As #1
'Boucle sur les lignes du fichier
Do While Not EOF(1)
Line Input #1, strLigne
str() = Split(strLigne, ";") 'séparateur ;
'Pour chaque colonne
For i = 0 To UBound(str)
Cells(Ligne, i + 1).Value = str(i)
Next i
Ligne = Ligne + 1
Loop
Close #1
End Sub |
Partager