Insertion du graphique dans le userform - erreur

Résolu
Ecaterina -  
 Ecaterina -
Bonjour!

Encore une fois je pose la question, car je suis débutante en VBA et je ne connais pas encore tout.

J'ai un souci, car j'ai trouvé un code pour insérer le graphique dans l'userform (dans plusieurs sources) et pourtant ce code ne marche pas dans mon cas. Le code est le suivant:



Private Sub CommandButton1_Click()
'afficher le graphique dans l'userform

Dim Legraph As Chart

Set Legraph = Worksheets("Graphiques").ChartObjects(1).Chart
fichier = ActiveWorkbook.Path & "\" & "graphe.gif"
Legraph.Export Filename:=fichier, FilterName:="GIF"
Image1.picture = LoadPicture(fichier)
Kill fichier

End Sub

Pourriez-vous m'indiquer l'erreur qui se produit s'il vous plait?
Voici mon fichier: https://www.cjoint.com/c/KCsw1Dlh0XD
A voir également:

2 réponses

f894009 Messages postés 17272 Date d'inscription   Statut Membre Dernière intervention   1 713
 
Bonjour,

Il y avait l'erreur variable non definie avec
Option Explicit
au debut . Il faut donc definir toutes les variables

Option Explicit

Private Sub CommandButton1_Click()
    'afficher le graphique dans l'userform
    
    Dim Legraph As Chart
    Dim Fichier
    
    Set Legraph = Worksheets("Graphiques").ChartObjects(1).Chart
    Fichier = ActiveWorkbook.Path & "\" & "graphe.gif"
    Legraph.Export Filename:=Fichier, FilterName:="GIF"
    Image1.Picture = LoadPicture(Fichier)
    Kill Fichier
    
End Sub
1
Ecaterina
 
Merci beaucoup, ça marche!
0