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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Sub Triangle(Ftriangle As Shape, pct() As Double, No As Integer, NomFeuille As String, text As String)
Const Largeur = 150
Const Hauteur = ((3 / 4) * (Largeur ^ 2)) ^ (1 / 2) 'Pour que le triangle soit équilatéral
Dim Feuille As Worksheet
Dim lineL As Double, lineT As Double, LineW As Double, LineH As Double
Dim Coin1G As Double, coin1H As Double, Coin2G As Double, Coin2H As Double
Dim Forme1 As Shape, Forme2 As Shape
'coin en haut à gauche
Coin1G = Ltxt + (Largeur + Ltxt * 2) * ((No - 1) Mod 4)
coin1H = Htxt + (Hauteur + Htxt * 2) * (1 + Fix((No - 1) / 4))
'coin en bas à gauche
Coin2G = Coin1G
Coin2H = coin1H + Hauteur
Set Feuille = ThisWorkbook.Worksheets(NomFeuille)
Set Forme1 = _
Feuille.Shapes.AddShape(msoShapeRectangle, _
Coin1G, coin1H, Largeur, Hauteur) 'le rectange
Set Forme2 = _
Feuille.Shapes.AddShape(msoShapeIsoscelesTriangle, _
Coin1G, coin1H, Largeur, Hauteur) 'le triangle
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Forme2.Name)).Group
'on fusionne les 2 formes
'Pour le 1° %
'-----------------------------------------------
lineL = Coin1G + Largeur * pct(1)
lineT = Coin2H
LineW = lineL + Largeur * (1 - pct(1)) / 2
LineH = lineT + Hauteur * (pct(1) - 1)
Set Forme1 = Feuille.Shapes.AddLine(lineL, lineT, LineW, LineH)
Forme1.Line.ForeColor.RGB = RGB(120, 225, 34)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
Set Forme1 = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, Coin2G, Coin2H, Ltxt, Htxt)
Call legende_ligne(Forme1, "0", 1)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
Set Forme1 = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, Coin2G + Largeur, Coin2H, Ltxt, Htxt)
Call legende_ligne(Forme1, "100%", 1)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
'Pour le 2° %
'------------------------------------
lineL = Coin1G + Largeur * pct(2) / 2
lineT = coin1H + Hauteur * (1 - pct(2))
LineW = lineL + Largeur * (1 - pct(2))
LineH = lineT
Set Forme1 = Feuille.Shapes.AddLine(lineL, lineT, LineW, LineH)
Forme1.Line.ForeColor.RGB = RGB(43, 101, 226)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
Set Forme1 = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, Coin2G + Largeur, Coin2H - Htxt, Ltxt, Htxt)
Call legende_ligne(Forme1, "0", 2)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
Set Forme1 = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, Coin1G + Largeur / 2, coin1H, Ltxt, Htxt)
Call legende_ligne(Forme1, "100%", 2)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
'Pour le 3° %
'--------------------------------------------------------
lineL = Coin1G + Largeur * (1 - pct(3)) / 2
lineT = coin1H + Hauteur * pct(3)
LineW = Coin2G + Largeur * (1 - pct(3))
LineH = Coin2H
Set Forme1 = Feuille.Shapes.AddLine(lineL, lineT, LineW, LineH)
Forme1.Line.ForeColor.RGB = RGB(120, 0, 255)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
Set Forme1 = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, Coin1G + Largeur / 2 - Ltxt, coin1H, Ltxt, Htxt)
Call legende_ligne(Forme1, "0", 3)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
Set Forme1 = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, Coin2G, Coin2H - Ltxt, Ltxt, Htxt)
Call legende_ligne(Forme1, "100%", 3)
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
'--------------------------------------------
'La zone de texte associée au triangle
Set Forme1 = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, Coin1G, coin1H - Htxt, Largeur, Htxt)
Forme1.TextFrame.Characters.text = text
Set Ftriangle = Feuille.Shapes.Range(Array(Forme1.Name, Ftriangle.Name)).Group
End Sub
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Sub legende_ligne(forme As Shape, text As String, No As Integer)
'Pour mettre en forme une forme
With forme
.TextFrame.Characters.text = text
.TextFrame.AutoSize = True
Select Case No
Case 1: .TextFrame.Characters.Font.Color = RGB(120, 225, 34)
Case 2: .TextFrame.Characters.Font.Color = RGB(43, 101, 226)
Case 3: .TextFrame.Characters.Font.Color = RGB(120, 120, 120)
Case 4: .TextFrame.Characters.Font.Color = RGB(255, 0, 255)
Case Else: .TextFrame.Characters.Font.Color = RGB(20, 20, 34)
End Select
.Fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
End Sub
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Sub ajouter_point(Ftriangle As Shape, pct() As Double, noPoint As Integer)
Const TaillePt = 5
Dim lineL As Double, lineT As Double
Dim Point As Shape
Dim Feuille As Worksheet
Dim Nocouleur As Long
'la couleur du point
Select Case noPoint
Case 1: Nocouleur = RGB(120, 225, 34)
Case 2: Nocouleur = RGB(43, 101, 226)
Case 3: Nocouleur = RGB(120, 120, 120)
Case 4: Nocouleur = RGB(255, 0, 255)
Case Else: Nocouleur = RGB(20, 20, 34)
End Select
Set Feuille = Worksheets(Ftriangle.TopLeftCell.Worksheet.Name)
'la feuille de la forme du triangle
'Ses coordonnées
lineL = Ftriangle.Left + (Ftriangle.Width - Ltxt) * ((pct(2) / 2) + pct(1))
lineT = Ftriangle.Top + Htxt + (Ftriangle.Height - 2 * Htxt) * (1 - pct(2))
'on le crèe et le met en forme
Set Point = Feuille.Shapes.AddShape(msoShapeOval, lineL - TaillePt / 2, lineT + TaillePt / 2, TaillePt, TaillePt)
Point.Line.Weight = TaillePt
Point.Line.ForeColor.RGB = Nocouleur
Point.Line.BackColor.RGB = Nocouleur
Set Ftriangle = Feuille.Shapes.Range(Array(Point.Name, Ftriangle.Name)).Group
'La légende
lineL = Ftriangle.Left
lineT = Ftriangle.Top + Htxt * ((noPoint + 1) / 2)
Set Point = Feuille.Shapes.AddTextbox(msoTextOrientationHorizontal, lineL, lineT, TaillePt, TaillePt)
Call legende_ligne(Point, CStr(noPoint), noPoint)
Point.TextFrame.Characters.Font.Bold = True
Set Ftriangle = Feuille.Shapes.Range(Array(Point.Name, Ftriangle.Name)).Group
End Sub |
Partager