Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 31/08/2011, 16h23   #1
Invité de passage
 
Homme Matthieu
technicien laboratoire
Inscription : juillet 2011
Messages : 1
Détails du profil
Informations personnelles :
Nom : Homme Matthieu
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : technicien laboratoire
Secteur : Industrie

Informations forums :
Inscription : juillet 2011
Messages : 1
Points : 0
Points : 0
Par défaut création d'un graphique 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 :

Code :
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
matraveler est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/08/2011, 16h30   #2
Membre actif
 
Inscription : novembre 2008
Messages : 188
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 188
Points : 194
Points : 194
Remplace:

Code :
ActiveChart.SetSourceData Source:=Sheets("Feuil1")
par:

Code :
ActiveChart.SetSourceData Source:=ActiveSheet
Pour accélérer l'exécution de la macro, rajoute ceci au tout début du code:

Code :
Application.ScreenUpdating = False
Et cela à la fin:

Code :
Application.ScreenUpdating = True


PS: n'oublie pas d'utiliser les balises [CODE] quand tu postes...
Sclarckone est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 21h45.


 
 
 
 
Partenaires

Hébergement Web