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 79 80 81 82 83 84 85
|
' Ajouter la référence à Microsoft Excel ...
' Declarations Excel
Dim objXL As Excel.Application, objSheet As Object '
Dim fichierModeleXL As String, nomSauvegarde As String
Dim grpApp As Graph.Chart
On Error GoTo Err_Click
Set grpApp = Me.xChart2.Object
grpApp.Export Application.CurrentProject.Path & "\graphe2.gif", FilterName:="GIF"
Set grpApp = Nothing
Me.xChart2.Action = acOLEClose 'nécessaire sinon erreur OLE :: http://support.microsoft.com/kb/824276/fr
' 'avec Enabled=OUI
Me.Requery 'cette ligne si besoin ...
' *** EXCEL ***
Ouvre_feuille_excel: '(si l'appli Excel est déjà lancée)
On Error GoTo err_init_excel
Set objXL = GetObject(, "Excel.application") ' référence vers appli Excel
On Error GoTo err_quit_excel
objXL.Visible = True
'objXL.Workbooks.Add ' ouvre nouveau fichier .xls
fichierModeleXL = Application.CurrentProject.Path & "\XLS\modeleXLS.xls"
objXL.Workbooks.Open (fichierModeleXL) ' ouvre fichier modele existant
'si Excel en icône, on le ré-ouvre
If objXL.WindowState = xlMinimized Then objXL.WindowState = xlNormal
Set objSheet = objXL.ActiveSheet
objSheet.Activate
objXL.ActiveSheet.Cells(2, 3).Value = "CECI EST MON TITRE"
objXL.ActiveSheet.Pictures.Insert(Application.CurrentProject.Path & "\graphe2.gif").Select
'on déplace le graphe au bon endroit
objXL.ActiveSheet.Pictures.ShapeRange.IncrementLeft 76.5
objXL.ActiveSheet.Pictures.ShapeRange.IncrementTop 39.75
' ********* Fin écriture dans EXCEL **************
'Sauvegarde du fichier
'-----------------------
'constitution du chemin/nom de fichier
nomSauvegarde = Application.CurrentProject.Path & "\testXls" & "_édité_le_" & Format(Date, "dd\-mm\-yyyy") & ".xls"
'on sauvegarde la feuille sous le nom contenu dans nomSauvegarde
objXL.ActiveWorkbook.SaveAs Filename:=nomSauvegarde, _
FileFormat:=17, password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
'Si on voulait quitter excel :
'objXL.Application.Quit
Set objSheet = Nothing
Set objXL = Nothing
Exit_Click:
Exit Sub
err_init_excel:
On Error GoTo Err_Click
Set objXL = CreateObject("Excel.application") ' nouvelle instance Excel
GoTo Ouvre_feuille_excel
err_quit_excel:
MsgBox " Impossible d'ouvrir le fichier " & fichierModeleXL
objXL.Quit
Set objXL = Nothing
GoTo Err_Click
Err_Click:
MsgBox Err.Description, vbCritical, "Erreur n°" & Err.Number
Resume Exit_Click |
Partager