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
|
Dim CurrentChart, Fname, agents, choixAnnée, i 'déclaration des variables CurrentChart et Fname
Private Sub UserForm_Initialize() 'au demarage le formulaire
Me.ListBox1.MultiSelect = fmMultiSelectMulti
Set choixAnnée = Sheets("Agents") ' variable enleve la croix rouge (fonction et décalaration dans le module 1)
Set agents = Sheets("Agents") ' variable Agents =
Me.choix.List = Range(agents.[a2], agents.[a65000].End(xlUp)).Value 'remplir liste des séquences
Me.Année.List = Range(choixAnnée.[d2], choixAnnée.[d65000].End(xlUp)).Value
Me.ListBox1.List = Range(choixAnnée.[d2], choixAnnée.[d65000].End(xlUp)).Value
End Sub
Private Sub ListBox1_Change()
Static nb As Integer
Dim choisi As Integer, max As Integer
max = 3 ' tu mets ici la valeur que tu veux (nombre maxi de sélmections autorisées)
choisi = ListBox1.ListIndex
If ListBox1.Selected(choisi) = False Then nb = nb - 1: Exit Sub
If nb >= max Then ListBox1.Selected(choisi) = False
nb = nb + 1
If nb > 0 Then
CommandButton8 = True
Else
CommandButton8 = False
End If
End Sub
Private Sub CommandButton8_Click() 'courbe nb jours
Call Compte_jours ' applique la procédure (compte jours décalaration dans lemodule 2)
'Sheets("courbe jours").Select ' active la feuille contenant le graphique la feuille s'appelle courbe jours
ActiveWorkbook.RefreshAll ' raffraichir les données du tableau croisé dynamique
Dim x As Integer
Dim i As Integer
' on place tous à true
With Sheets("courbe jours").PivotTables("Tableau croisé dynamique1").PivotFields( _
"année")
For i = 0 To ListBox1.ListCount - 1
If ListBox1.List(i) <> "" Then
PivotItems(ListBox1.List(i)).Visible = True
End If
Next i
For i = 0 To ListBox1.ListCount - 1
If ListBox1.List(i) <> "" Then
If ListBox1.Selected(i) = False Then
.PivotItems(ListBox1.List(i)).Visible = False
Else
.PivotItems(ListBox1.List(i)).Visible = True
End If
End If
Next i
Application.ScreenUpdating = True 'active la mise à jour de l'écran
Set CurrentChart = Sheets("courbe jours").ChartObjects(1).Chart ' référencé l'objet CurrentChart, là dans l'exemple, c'est le 1er graphique "ChartObjects(1)"
Sheets("courbe jours").ChartObjects("Graphique 1").Activate ' active le graphique qui s'appelle "Graphique 1"
ActiveChart.ChartArea.Select
ActiveChart.ShowWindow = True
Fname = ThisWorkbook.Path & "\temp2.gif" ' attribution d'un nom pour l'export du graphique, dans le dossier courant du fichier
CurrentChart.Export Filename:=Fname, FilterName:="GIF"
UserForm1.Image1.Picture = LoadPicture(Fname) ' ensuite j'ai créé un UserForm (userform6) avec juste une image (vierge, qui s'appelle Image1), qui charge donc l'image venant d'être enregistré.
End With
End Sub |