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 :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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 reste à votre disposition pour tous compléments d'information ou clarification du sujet.

merci à vous