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
| Function ImportDonnéesXL()
Dim fDialog As Office.FileDialog
Dim strChemin As Variant, strNomfichier As String, strNomfichier1 As String
Dim strSql As String
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = True
.Title = "Choisir les fichiers à importer"
.Filters.Clear
.Filters.Add "Fichiers Excel", "*.xlsx, *.xls"
If .Show = True Then
'on boucle sur la sélection de fichiers Excel
For Each strChemin In .SelectedItems
'on récupère le nom du fichier avec son extension
strNomfichier = Dir(strChemin)
'on récupère le nom du fichier sans extension
strNomfichier1 = Left(strNomfichier, InStrRev(strNomfichier, ".xls") - 1)
'on utilise la méthode ci-dessous pour importer les données Excel
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "tblImportExcel", strChemin, True
'on exécute une requête de mise à jour pour associer NumTel avec NomFichier
'si extension placer strNomfichier, sans extension placer strNomfichier1
Next
Else
MsgBox "Importation annulée"
End If
End With
End Function |
Partager