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 41 42 43 44 45 46 47 48 49 50 51 52
|
Public Sub ImportExcel (strfichier as string)
on errer goto fini
'Déclaration des variables
Dim appExcel As Excel.Application 'Application Excel
Dim wbExcel As Excel.Workbook 'Classeur Excel
Dim wsExcel As Excel.Worksheet 'Feuille Excel
Set appExcel = CreateObject("Excel.Application")
appExcel.Visible = False
Set wbExcel = appExcel.Workbooks.Open(strFichier)
Set wsExcel = wbExcel.Sheets("Résultats")
i = 1
Do While i <= 75
appExcel.Cells(5, i) = "Champ" & i
i = i + 1
Loop
wbExcel.Save
wbExcel.Close 'Fermeture du classeur Excel
appExcel.Quit
'transfert
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "SasClient", strFichier, True, "A5:BW"
exit sub
fini :
wbExcel.Close 'Fermeture du classeur Excel
appExcel.Quit 'Fermeture de l'application Excel
'Désallocation mémoire
Set wsExcel = Nothing
Set wbExcel = Nothing
Set appExcel = Nothing
Select Case Err
Case 2220
MsgBox "L'importation du fichier ne s'est pas effectué normalement.", _
vbCritical, "Erreur fichier "
Case Else
msgbox & Err.Number & Chr(13) & Err.Description
End Select
end sub |