Public sub import()
Dim DB As Database, rest As Recordset
Set DB = CurrentDb
Set enregistrement = DB.OpenRecordset("Data")
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheets As Excel.Worksheet
Dim ligne as double
Dim numclient as double
Dim nom as string
Dim prenom as string
Dim cp as long
Dim ville as string
ligne = range("A65536").end(xlup).row
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\client.xls")
Set xlSheets = xlBook.Worksheets(1)
for i = 2 to ligne 'je part de deux car je met la première ligne du tableau excel comme noms des colonnes
xlSheets.cells(i,1).value = Numclient
xlSheets.cells(i,2).value = Nom
xlSheets.cells(i,3).value = prenom
xlSheets.cells(i,4).value = CP
xlSheets.cells(i,5).value = ville
With enregistrement
.AddNew
![Numclient] = Numclient
![Nom] = Nom
![Prenom] = Prenom
![CP] = CP
![Ville] = Ville
.Update
End With
Next
DB.Close
'Fermeture d'Excel
xlBook.Close False
xlApp.Quit
'Désallocation mémoire
Set xlSheets = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End sub