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 40
|
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
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acImport, 8, "T_INSCRIPTION", strChemin, True, "A1:C2000"
DoCmd.SetWarnings True
MsgBox "Opération terminée !", vbInformation
Exit Sub
ImportExcelErr:
MsgBox "Erreur d'importation : " & Err.Description, vbExclamation
Exit Sub
End Sub |
Partager