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
| ' ---
' IMPORTATION DE PLUSIEURS FEUILLES EXCEL
' ---
Sub ImportExcel(ByVal strChemin As String, ByVal varFeuilles As Variant, ByVal blnNoms As Boolean, ByVal strTable As String)
' Déclaration des variables
Dim strFeuille As Variant
' Est-ce que le classeur Excel existe ?
If Dir(strChemin) = "" Then
MsgBox "Le classeur ['" & strChemin & "] est introuvable.", vbExclamation
Exit Sub
End If
' Vidage de la table si nécessaire
On Error GoTo ImportExcelErr
If MsgBox("Souhaitez-vous vider la table [" & strTable & "] avant l'importation ?", vbQuestion + vbYesNo) = vbYes Then
CurrentDb.Execute "DELETE * FROM [" & strTable & "];"
End If
' Procédure d'importation
For Each strFeuille In varFeuilles
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, strTable, strChemin, blnNoms, strFeuille & "!"
Next
' Un p'tit message pour terminer :-)
MsgBox "Opération terminée !", vbInformation
Exit Sub
ImportExcelErr:
MsgBox "Erreur d'importation : " & Err.Description, vbExclamation
Exit Sub
End Sub |
Partager