Erreur automation , je veux afficher un graphique dans mon userf

Résolu/Fermé
amiro2017 Messages postés 194 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 - 12 mars 2017 à 16:09
amiro2017 Messages postés 194 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 - 13 mars 2017 à 12:05
bonjour le forum,

je suis débutant en vba et je n'arrive pas à afficher mon courbe qui est déjà crée dans mon userform et une erreur d'automation s'affiche lors de l'éxecution

voici le code:

Private Sub UserForm_Initialize()
Dim choix
    Set choix = Range("A1").CurrentRegion
    Charts.Add
    With ActiveChart
        .ChartType = xlLine
        .SetSourceData Source:=Sheets("Feuil2").Range("A1:A20,B1:B20")
        .Location Where:=xlLocationAsObject, Name:="Feuil2"
        .HasTitle = True
        .ChartTitle.Characters.Text = "courbe"
    End With
   'Supprime l'image temportaire si elle existe
   If Dir(Fichier) <> "" Then Kill Fichier
    'Définit le 1er graphique de la Feuil1
    'exporte le graphique au format image
    Worksheets("Feuil2").ChartObjects(1). _
        Chart.Export courbe:=Fichier, filtername:="GIF"
    'Affiche l'image dans l'UserForm
    Image1.Picture = LoadPicture(Fichier)
End Sub

je vous remercie d'avance
A voir également:

4 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
13 mars 2017 à 10:52
Bonjour,

comme ceci:

Private Sub UserForm_Initialize()
 Dim Chemin As String
 Chemin = ThisWorkbook.Path & "\mongraph.gif"
  Sheets("Feuil1").ChartObjects("Graphique 2").Chart.Export Chemin, "GIF" 'adapter feuille et nom graphique
   Image1.Picture = LoadPicture(Chemin)
   Kill Chemin
 End Sub

1
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
13 mars 2017 à 11:27
Prendre le nom ici:



1
amiro2017 Messages postés 194 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 1
13 mars 2017 à 11:11
Bonjour cs_Le Pivert ,

je vous remercie d'abord pour votre réponse et votre effort , cependant voici ce que j'ai eu malhereusement


la courbe n'est pas affiché dans mon userform et voici le code encore que j'ai utilisé:
Private Sub UserForm_Initialize()
   Dim Chemin As String
   Dim choix
    Set choix = Range("A1").CurrentRegion
    Charts.Add
    With ActiveChart
        .ChartType = xlLine
        .SetSourceData Source:=Sheets("Feuil2").Range("A1:A20,B1:B20")
        .Location Where:=xlLocationAsObject, Name:="Feuil2"
        .HasTitle = True
        .ChartTitle.Characters.Text = "courbe"
    End With
 Chemin = ThisWorkbook.Path & "\mongraph.gif"
  Sheets("Feuil2").ChartObjects("courbe").Chart.Export Chemin, "GIF" 'adapter feuille et nom graphique
   Image1.Picture = LoadPicture(Chemin)
   Kill Chemin
 End Sub


je vous remercie d'avance
0
amiro2017 Messages postés 194 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 1
Modifié par amiro2017 le 13/03/2017 à 11:41
vraiment c'est bizarre
le code est -il comme ceci?
.HasTitle = True
        .ChartTitle.Characters.Text = "Graphique1"
    End With
 Chemin = ThisWorkbook.Path & "\Graphique1.gif"
  Sheets("Feuil2").ChartObjects("Graphique1").Chart.Export Chemin, "GIF" 'adapter feuille et nom graphique
   Image1.Picture = LoadPicture(Chemin)
   Kill Chemin

voici c'est que j'ai eu
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
13 mars 2017 à 11:46
Il manque un espace

"Graphique1"

"Graphique 1"

voir mon code!!!!
0
amiro2017 Messages postés 194 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 1 > cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024
13 mars 2017 à 12:05
ohhh je vous remercie infinement cs_Le Pivert !!! ca marche !!
0