XL 2016 Autre curiosité ComboBox

  • Initiateur de la discussion Initiateur de la discussion Dudu2
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Dudu2

XLDnaute Barbatruc
Bonjour,

J'aimerais que le ComboBox.DropDown s'exécute automatiquement à chaque fois qu'on entre dans une ComboBox.
J'ai donc codé:
VB:
Private Sub UserForm_Initialize()
    Me.ComboBox1.List = [A1:A3].Value
    Me.ComboBox2.List = [B1:B3].Value
    Me.ComboBox3.List = [C1:C3].Value
    Me.ComboBox1.SetFocus
End Sub

Private Sub ComboBox1_Enter()
    [I2].Value = "ComboBox1_Enter"
    Me.ComboBox1.DropDown
End Sub

Private Sub ComboBox2_Enter()
    [I2].Value = "ComboBox2_Enter"
    Me.ComboBox2.DropDown
End Sub

Private Sub ComboBox3_Enter()
    [I2].Value = "ComboBox3_Enter"
    Me.ComboBox3.DropDown
End Sub

Hélas ! Quand on utilise Tabulation pour passer à la ComboBox suivante, le ComboBox.DropDown ne s'exécute qu'une fois sur 2. Et pourquoi donc ?
 

Pièces jointes

Solution
purée dudu2 si tu continu a filer mauvais cotton tu va m'entendre chanter toi !!!!😛
VB:
Private Sub UserForm_Initialize()
   Me.ComboBox1.List = [A1:A3].Value
   Me.ComboBox2.List = [B1:B3].Value
   Me.ComboBox3.List = [C1:C3].Value
End Sub

Private Sub ComboBox1_Enter()
    CreateObject("wscript.shell").SendKeys "{F4}" 'DropDown
End Sub

Private Sub ComboBox2_Enter()
 CreateObject("wscript.shell").SendKeys "{F4}" 'DropDown
End Sub

Private Sub ComboBox3_Enter()
 CreateObject("wscript.shell").SendKeys "{F4}" 'DropDown
End Sub
Ce qui est sûr c'est que je garde ces acquis pour mon usage perso quand je développe des trucs pour les gens.
Ces 2 curiosités des ComboBoxes qui nous ont occupés une partie de l'après-midi, franchement j'aurais jamais pensé tomber dessus. Et maintenant que je sais comment les identifier / contourner, je vais pas me priver 😉.

Et je suis content d'avoir eu le support des experts qui se sont impliqués. Merci à eux !
 
oui il y en a quelques uns comme ça qui sont intéressants les plus dur sont sur feuille
tiens un autre en deux temps
1er tab dropdown et le 2d sélectionne la suivante
VB:
Private Sub UserForm_Initialize()
    Me.ComboBox1.List = [A1:A3].Value
    Me.ComboBox2.List = [B1:B3].Value
    Me.ComboBox3.List = [C1:C3].Value
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    key_tabpress ComboBox1, KeyCode
End Sub

Private Sub ComboBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    key_tabpress ComboBox2, KeyCode
End Sub

Private Sub ComboBox3_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    key_tabpress ComboBox3, KeyCode
End Sub

Private Sub key_tabpress(combo As MSForms.ComboBox, ByVal KeyCode As MSForms.ReturnInteger)
    With combo
        If KeyCode = 9 And Val(.Tag) = 0 Then .Tag = 1: KeyCode = 0: .DropDown Else .Tag = 0
    End With
End Sub
 
re
le tag c'est surtout pratique pour memeriser un flag respectif a chaque combobox
on peut faire avec une variable tableau
VB:
Dim flag&(1 To 3)
Private Sub UserForm_Initialize()
    Me.ComboBox1.List = [A1:A3].Value
    Me.ComboBox2.List = [B1:B3].Value
    Me.ComboBox3.List = [C1:C3].Value
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    key_tabpress ComboBox1, KeyCode, flag(1)
End Sub

Private Sub ComboBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    key_tabpress ComboBox2, KeyCode, flag(2)
End Sub

Private Sub ComboBox3_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    key_tabpress ComboBox3, KeyCode, flag(3)
End Sub

Private Sub key_tabpress(combo As MSForms.ComboBox, ByVal KeyCode As MSForms.ReturnInteger, flag&)
    With combo
        If KeyCode = 9 And Val(flag) = 0 Then flag = 1: KeyCode = 0: .DropDown Else flag = 0
    End With
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
3
Affichages
665
Réponses
3
Affichages
504
Réponses
3
Affichages
298
Réponses
6
Affichages
604
Retour