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
| Option Explicit
Public Const nameBarRestit = "TabRestit" ' Barre d'outil "Tableaux des restitutions"
Public Const indTlbAbsRel = 1 ' Indice du premier bouton de la barre d'outil
Public Const indTlbVolVal = indTlbAbsRel + 1
'Public Const indTlbNextBtn = indTlbVolVal + 1 ' Prochain bouton
Function TlbRestit() As CommandBar ' Accès à la barre d'outil "TabRestit"
Set TlbRestit = CommandBars(nameBarRestit)
End Function
Sub ToolbarCreate()
Const rowTlb = 3, ctrlBtnId = 2950 ' type de bouton flip-flop persistant
Const indBtnCaption = 0, indBtnAction = 1, indBtnIcon = 2 ' Item dans le tableau arrBtn
Dim cmdTlb As CommandBar, cmdBtn As CommandBarButton
Dim indBtn As Byte, arrBtn As Variant ' Description de la barre d'outil
ToolbarDelete
Set cmdTlb = CommandBars.Add(nameBarRestit, msoBarTop, False, True)
' cmdTlb.RowIndex = rowTlb ' Peut décaler les toolbars par défaut d'Excel si visibles
arrBtn = Array(Array("Valeur absolue", "AbsRel", 205), _
Array("Restitution en valeur", "VolVal", 16))
For indBtn = LBound(arrBtn) To UBound(arrBtn) ' Pour chaque description de boutons
Set cmdBtn = cmdTlb.Controls.Add(Type:=msoControlButton, Id:=ctrlBtnId) ' Crée le bouton
With cmdBtn ' Initialisation commune de chaque bouton
.FaceId = arrBtn(indBtn)(indBtnIcon) ' Icon du bouton
.Style = msoButtonIconAndCaption
.Caption = arrBtn(indBtn)(indBtnCaption)
.OnAction = "Btn" + arrBtn(indBtn)(indBtnAction) + "Click"
Select Case .Index
Case indTlbVolVal ' Initialisation particulière d'un bouton donné
.BeginGroup = True ' Si on veut un séparateur de groupe de boutons
.State = msoButtonDown ' "Restitution en valeur" down par défaut
End Select
End With
Next
cmdTlb.Visible = True
End Sub
Sub ToolbarDelete()
On Error Resume Next
TlbRestit().Reset
TlbRestit().Delete
On Error GoTo 0
End Sub
Private Sub BtnAbsRelClick() ' Clic sur le bouton "Valeur absolue / relative"
With TlbRestit.Controls(indTlbAbsRel)
If .State = msoButtonDown Then
.State = msoButtonUp
.Caption = "Valeur absolue"
Else
.State = msoButtonDown
.Caption = "Valeur relative"
End If
End With
End Sub
Private Sub BtnVolValClick() ' Clic sur le bouton "Restitution en volume / valeur"
With TlbRestit.Controls(indTlbVolVal)
If .State = msoButtonDown Then
.State = msoButtonUp
.Caption = "Restitution en volume"
Else
.State = msoButtonDown
.Caption = "Restitution en valeur"
End If
End With
End Sub
Sub ShowFaceIDs() ' Display the available FaceIDs of toobar buttons
Const ctrlBtnId = 2950, indIdStart = 1, indIdStop = 250
Dim cmdTlb As CommandBar, cmdBtn As CommandBarButton, indFaceId As Integer
On Error Resume Next
Application.CommandBars("FaceIds").Delete
On Error GoTo 0
Set cmdTlb = Application.CommandBars.Add(Name:="FaceIds", temporary:=True)
cmdTlb.Visible = True
For indFaceId = indIdStart To indIdStop
Set cmdBtn = cmdTlb.Controls.Add(Type:=msoControlButton, Id:=ctrlBtnId)
cmdBtn.FaceId = indFaceId
cmdBtn.Caption = "FaceID = " & indFaceId
Next
cmdTlb.Width = 600
End Sub |
Partager