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
| Sub AddListe(Source As Range, Cible As Range)
Dim SH As Shape
Dim DD As DropDown
Dim var
'---
var = Split(Source, ";")
If UBound(var) < 0 Then Exit Sub
'--- Création d'une Shape ---
Set SH = ActiveSheet.Shapes.AddFormControl(xlDropDown, Cible.Left, Cible.Top, Cible.Width, Cible.Height)
SH.OnAction = "DropDownSurClic"
SH.Name = "___pmo"
'--- Récupération du réel objet DropDown ---
Set DD = SH.OLEFormat.Object
DD.DropDownLines = 12
'--- Affichage des items dans le DropDown ---
If UBound(var) = 0 Then
DD.AddItem var(0)
Else
DD.List = var
End If
'--- Sélection du Range appelant ---
Cible.Select
End Sub
Sub DropDownSurClic(Optional dummy As Byte) '### Evènement Clic sur le DropDown ###
Dim SH As Shape
Dim DD As DropDown
Dim R As Range
'--- Recherche du DropDown ---
On Error Resume Next
Set SH = ActiveSheet.Shapes("___pmo")
If Err <> 0 Then Exit Sub
Set DD = SH.OLEFormat.Object
'--- Inscription de la sélection du DropDown ---
Set R = ActiveCell
R = DD.List(DD)
'--- Destruction du DropDown ---
Call DelDropDown
End Sub
Sub DelDropDown(Optional dummy As Byte) '### Destruction du DropDown ###
Dim SH As Shape
On Error Resume Next
Set SH = ActiveSheet.Shapes("___pmo")
If Not SH Is Nothing Then SH.Cut
End Sub |
Partager