Fermeture d'excel par VBA ACCESS
Bonjour tout le monde,
Je vien chercher de l'aide car malgrés mes effor je ne trouve pas la solution à mon probléme.
J'ai un bou de code qui ouvre une aplication Excel et ouvre et ferme succesivement des workbooks. à la fin de cette boucle (infernale j'aimerai qu'il finisse par fermer Excel (de sorte à ce qu'il n'apparaisse pas dans les processus du gestionnaire des taches).
Voila mon code:
Code:
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| Public Function IMPORT_GLOBAL()
'//////// IMPORT DU FICHIER ET SELECTION \\\\\\\\\
'Ce code permet de récupérer les données dans chaque fichier excel, cela peut prendre un peu de temps car il doit mettre à jour 12 TCD par fichier
'Pour séléctionner les fichier fournisseur il se base sur la liste des fournisseur à noter
Dim lgClients As Long, lgIdx As Long
Dim strSQL As String
Dim LibFournisseur As String
Dim CodeFournisseur As String
Dim Onglet As String
Dim myPath As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
lgClients = DCount("*", "R_Select_Fourn")
If lgClients = 0 Then Exit Function
Set xlApp = New Excel.Application
xlApp.Visible = False
For lgIdx = 1 To lgClients
DoCmd.SetWarnings False
' Vide SelectionFournisseur
DoCmd.RunSQL "DELETE FROM [Selection_Fourn]"
' Met Nième LibFournisseur dans SelectionFournisseur
strSQL = "INSERT INTO Selection_Fourn([Nom Fournisseur]) " & _
"SELECT Max([Nom Fournisseur])" & _
"FROM (SELECT TOP " & lgIdx & " [Nom Fournisseur] FROM R_Select_Fourn)"
DoCmd.RunSQL strSQL
' Attribution du code fournisseur inséré dans la table Selection_Fourn à la variable LibFournisseur
LibFournisseur = CurrentDb.OpenRecordset("Selection_Fourn").Fields(0).Value
CodeFournisseur = CurrentDb.OpenRecordset("Code_Fournisseur_Séléctionné").Fields(0).Value
'MsgBox (LibFournisseur)
DoCmd.SetWarnings True
'Adress du fichier pour l'import
myPath = "U:\Notations Fournisseurs et Plans d'actions\Logistique\EVALUATION AC 2010\Evaluation Fournisseur -" & LibFournisseur & "- .xls"
Set xlBook = xlApp.Workbooks.Open(myPath)
Set xlsheet = xlBook.Worksheets("TCD")
xlsheet.PivotTables("TCDjanvier").PivotCache.Refresh
xlsheet.PivotTables("TCDfévrier").PivotCache.Refresh
xlsheet.PivotTables("TCDmars").PivotCache.Refresh
xlsheet.PivotTables("TCDavril").PivotCache.Refresh
xlsheet.PivotTables("TCDmai").PivotCache.Refresh
xlsheet.PivotTables("TCDjuin").PivotCache.Refresh
xlsheet.PivotTables("TCDjuillet").PivotCache.Refresh
xlsheet.PivotTables("TCDaoût").PivotCache.Refresh
xlsheet.PivotTables("TCDseptembre").PivotCache.Refresh
xlsheet.PivotTables("TCDoctobre").PivotCache.Refresh
xlsheet.PivotTables("TCDnovembre").PivotCache.Refresh
xlsheet.PivotTables("TCDdécembre").PivotCache.Refresh
DoCmd.TransferSpreadsheet acImport, 8, "IMPORT_GLOBAL", myPath, True, "TCD!A86:G122"
xlBook.Save
xlBook.Close
Set xlsheet = Nothing
Set xlBook = Nothing
Next
Exit Function
Set xlsheet = Nothing
Set xlBook = Nothing
DoCmd.OpenQuery "SUP_IMPORT_GLOBAL_0CMD" 'Supprime les lignes de données ou le champ nb commande est à zero
Excel.Application.Quit
Set xlApp = Nothing
End Function |
Merci à tous pour votre aide future
Bien à vous
Alex