VBA problème avec nom des graphiques

Fermé
StagiaireVBA -  
 StagiaireVBA -
Bonjour,

J'ai un problème avec le nom de mes graphique. Voici mon code

Application.ScreenUpdating = False
Charts.Add
NomGraphe = ActiveChart.Name
MsgBox NomGraphe

ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Courbes - Histogramme"
ActiveChart.SetSourceData Source:=Sheets("Feuil1").Range("C4")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Feuil1!R15C5:R15C17"
ActiveChart.SeriesCollection(1).Values = "=Feuil1!R16C5:R16C17"
ActiveChart.SeriesCollection(1).Name = "=Feuil1!R16C3"
ActiveChart.SeriesCollection(2).XValues = "=Feuil1!R15C5:R15C17"
ActiveChart.SeriesCollection(2).Values = "=Feuil1!R17C5:R17C17"
ActiveChart.SeriesCollection(2).Name = "=Feuil1!R17C3"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Feuil1"

NomGraphe = ActiveChart.Name
MsgBox NomGraphe

With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False

End With
ActiveSheet.Shapes(NomGraphe).IncrementLeft -231#
ActiveSheet.Shapes(NomGraphe).IncrementTop 147.75

Application.Screanupdating = True
End Sub

Dans la première msgbox il me dit : Graph12 (et au prachain lancement ca sera graph13...)
dans la deuxieme il me dit : Feuil1 Graphique 19 (pourquoi? je ne lui ai pas dit de changer de nom!!!)
Et losque j'arrive à la ligne

ActiveSheet.Shapes(NomGraphe).IncrementLeft -231#

il m'affiche une erreur :

l'élément portant ce nom est introuvable.

Je ne sais pas comment faire?!

quelqu'un aurait une solution?

merci!

2 réponses

  1. Etpaflechien
     
    bonjour,
    tu peux essayer de remplacer, après ta première msgbox :

    ActiveChart. par Charts(NomGraphe).

    ?
    0
  2. StagiaireVBA
     
    Merci,

    J'ai essayé comme cela :

    Sub Macro3()
    Application.ScreenUpdating = False
    Charts.Add
    NomGraphe = ActiveChart.Name
    MsgBox NomGraphe

    ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
    "Courbes - Histogramme"
    Charts(NomGraphe).SetSourceData Source:=Sheets("Feuil1").Range("C4")
    Charts(NomGraphe).SeriesCollection.NewSeries
    Charts(NomGraphe).SeriesCollection.NewSeries
    Charts(NomGraphe).SeriesCollection(1).XValues = "=Feuil1!R15C5:R15C17"
    Charts(NomGraphe).SeriesCollection(1).Values = "=Feuil1!R16C5:R16C17"
    Charts(NomGraphe).SeriesCollection(1).Name = "=Feuil1!R16C3"
    Charts(NomGraphe).SeriesCollection(2).XValues = "=Feuil1!R15C5:R15C17"
    Charts(NomGraphe).SeriesCollection(2).Values = "=Feuil1!R17C5:R17C17"
    Charts(NomGraphe).SeriesCollection(2).Name = "=Feuil1!R17C3"
    Charts(NomGraphe).Location Where:=xlLocationAsObject, Name:="Feuil1"

    NomGraphe = ActiveChart.Name
    MsgBox NomGraphe

    With Charts(NomGraphe)
    .HasTitle = False
    .Axes(xlCategory, xlPrimary).HasTitle = False
    .Axes(xlValue, xlPrimary).HasTitle = False

    End With
    ActiveSheet.Shapes(NomGraphe).IncrementLeft -231#
    ActiveSheet.Shapes(NomGraphe).IncrementTop 147.75

    Application.Screanupdating = True
    End Sub

    Mais maintenant, lorsque j'arrive à

    With Charts(NomGraphe)

    il me dit "l'indice n'appartient pas a la selection" et le NomGraph a encore changé en cour de route...
    0