Graphique automatique via une macro
Bonjour,
débutant sous VBA, je cherche à réaliser une macro qui me permet de créer un graphique à partir d'un fichier X.
le programme obtenu est le suivant :
Sub graph_macro_2()
'
' graph_macro_2 Macro
' Macro enregistrée le 31/08/2011 par quintric
'
Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Feuil1"). _
Range("A18:B500"), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "courbe force course"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "course (mm)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "force (N)"
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 2
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).XValues = _
"='Feuil1'!R18C2:R500C2"
ActiveChart.SeriesCollection(1).Values = _
"='Feuil1'!R18C1:R500C1"
ActiveChart.Axes(xlValue).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MajorTickMark = xlOutside
.MinorTickMark = xlNone
.TickLabelPosition = xlNextToAxis
End With
ActiveChart.Axes(xlCategory).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MajorTickMark = xlOutside
.MinorTickMark = xlNone
.TickLabelPosition = xlNextToAxis
End With
With ActiveChart.Axes(xlCategory)
.MinimumScale = 0
.MaximumScaleIsAuto = True
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
End Sub
le programme fonctionne, seulement j'aurai besoin de remplacer Feuil1 automatiquement par le nom de celle du fichier a exploiter.
dans ce fichier, il n'y a qu'un seul onglet nommé comme le nom de sauvegarde.
pour résumer j'ai besoin que la macro s'exécute quelque soit le nom de la feuille qui contient mes mesures.
je joins un fichier de mesure au cas ou ca peut vous aider.
je reste à votre disposition pour tous compléments d'information ou clarification du sujet.
merci à vous
Bonjour,
Peut-être une piste :
Dim LaFeuille As Worksheet
Set LaFeuille = ActiveSheet
Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=LaFeuille. _
Range("A18:B500"), PlotBy:=xlColumnsEn déclarant une variable "LaFeuille"
Ici, j'ai mis "ActiveSheet"
Bon courage
Merci,
je vais essayé cela