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
| chemin_fichier = "c:\documents\..\fichier_xlsx"
nom_feuille = 'feuille1"
plage_donnees = "" ' facultatif
liste_colonnes = "champ1, champ2, champ3"
nom_table = "table_dest"
' si la table de destination n'existe pas
If Not TableExists(nom_table) Then ' création d'une nouvelle table
sSQL = "SELECT " & liste_colonnes & " INTO [" & nom_table & "] " & _
"FROM [Excel 8.0;HDR=YES;DATABASE=" & chemin_fichier & "].[" & nom_feuille & "$" & plage_donnees & "] AS T1 "
Else ' insert dans table existante
If MsgBox("Table déjà présente : Souhaitez-vous vider les données de la table de destination ?", vbYesNo) = vbYes Then
CurrentDb.Execute "delete from [" & nom_table & "]", dbFailOnError
End If
sSQL = "INSERT INTO [" & nom_table & "] " & _
"SELECT " & liste_colonnes & " " & _
"FROM [Excel 8.0;HDR=YES;DATABASE=" & chemin_fichier & "].[" & nom_feuille & "$" & plage_donnees & "] AS T1 "
End If
CurrentDb.Execute sSQL, dbFailOnError
' rafraîchit la fenêtre de navigation Access
Application.RefreshDatabaseWindow |
Partager