Problème pour la création d'un graphique
Bonjour,
Je suis débutant en VBA... ça fait depuis hier en fait lol
Je souhaite récupérer des données d'un fichier texte et les tracer dans un graphe nuage de points.
Pour l'instant j'ai écrit le code 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
| Sub Macro1()
'Récupérationd du fichier et importation
fichier = InputBox("entrez le nom du fichier")
ChDir "C:\Labview Fred"
Workbooks.Open Filename:=fichier
Attenuateur = InputBox("entrez la valeur de l'aténuateur")
Pertes_cable = InputBox("entrez la valeur des pertes câbles")
Frequence = Cells(1, 1)
Cells(1, 6) = "PIN corrigé (dBm)"
Cells(1, 7) = "POUT corrigé (dBm)"
A = 2
Do Until Cells(A, 1) = ""
Cells(A, 6) = Cells(A, 1) - Pertes_cable
A = A + 1
Loop
B = 2
Do Until Cells(B, 1) = ""
Cells(B, 7) = Cells(B, 2) + Attenuateur
B = B + 1
Loop
Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
'Mon programme ne marche pas à partir de là:
ActiveChart.SeriesCollection(1).XValues = "=fichier!R2C6:R12C6"
ActiveChart.SeriesCollection(1).Values = "=fichier!R2C7:R12C7"
ActiveChart.SeriesCollection(1).Name = "=""tata"""
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Graphique"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "tata"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Pin (dBm)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Pout (dBm)"
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = True
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlRight
'
End Sub |
En gros mon programme marche si je lui rentre directement le nom du fichier que j'ai sélectionné (ici "test2") à la ligne:
ActiveChart.SeriesCollection(1).XValues = "=test2!R2C6:R12C6"
Le problème est que je ne vais pas rentrer à chaque fois dans le soft le nom du fichier dans cette ligne...
Quelqu'un aurait'il une idée?
Merci