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
|
Sub ImportFichierCSV(RépertoireFichierAImporter, FichierAImporter, NomOngletImport)
Dim Cn As ADODB.Connection
Dim Repertoire As String
Dim Fichier As String
Dim texte_CON As String
Dim texte_SQL As String
Dim Rst As ADODB.Recordset
' RépertoireFichierAImporter = "E:\Mes documents\Idrissa\Moulinette Prose\"
' FichierAImporter = "Export_Plannings_SENP_2009_09.csv"
Set Cn = CreateObject("ADODB.Connection")
'--- Connection ---
texte_CON = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & RépertoireFichierAImporter & ";" _
& "Extended Properties=""text;HDR=NO;FMT=Delimited"";"
Cn.Open texte_CON
'-----------------
'Définit la requête.
texte_SQL = "SELECT * FROM " & FichierAImporter
Set Rst = New ADODB.Recordset
'Rst.Open strsql, cn
Set Rst = Cn.Execute(texte_SQL)
'création de l'onglet où seront copiées les données
Call AjoutNouvelOnglet(NomOngletImport)
'Ecrit le résultat de la requête dans la cellule A1 de l'onglet créé ligne précédente
Sheets(NomOngletImport).Select
Range("A1").CopyFromRecordset Rst
'--- Fermeture connexion ---
Cn.Close
Set Cn = Nothing
End Sub |
Partager