1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Sub ImportCSV()
Source = "C:\temp\Classeur1.csv"
Separateur = ";"
Destination_table = "Classeur1"
Destination_champs = "champ1,champ2,champ3,champ4"
Destination_champs_type = Array("""", "", """", "#") ' type: texte, numérique, texte, date
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(Source, 1)
DoCmd.SetWarnings False
Do While f.AtEndOfStream <> True
Champs = Split(Replace(Replace(f.ReadLine, "'", "''"), """", """"""), Separateur)
For i = 0 To UBound(Champs)
Champs(i) = Destination_champs_type(i) & Champs(i) & Destination_champs_type(i)
Next i
LeSQL = Join(Champs, ",")
LeSQL = "INSERT INTO " & Destination_table & "(" & Destination_champs & ") VALUES (" & LeSQL & ")"
DoCmd.RunSQL LeSQL
Loop
DoCmd.SetWarnings True
f.Close
End Sub |
Partager