XL 2016 Autre curiosité ComboBox

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

  • Classeur5.xlsm
    20.1 KB · Affichages: 25
Solution
purée dudu2 si tu continu a filer mauvais cotton tu va m'entendre chanter toi !!!!:p
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

Dudu2

XLDnaute Barbatruc
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 !
 

patricktoulon

XLDnaute Barbatruc
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
 

patricktoulon

XLDnaute Barbatruc
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
 

Discussions similaires

Réponses
6
Affichages
202
Réponses
4
Affichages
467