[Vba-E]Raccourci clavier selon focus

Résolu
Invite05 -  
 Invite05 -
Bonjour,

Je voudrai lorsque mon focus est sur textbox1, textbox2 etc... et qu'on appuit sur fait F2, aide_Userform s'affiche. j'ai essayé de développer quelque chose mais ca ne marche pas :

Sub enter()
If textbox1,textbox2, textbox3.setfocus
Application.OnKey Key:="{F2}", procedure:="aide"

End Sub

Sub hello()
aide.show
End Sub

Une idée?
merci!

2 réponses

  1. NicoDisso Messages postés 231 Statut Membre 32
     
    Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    if KeyCode = 113 then aide.show
    End Sub

    ensuite si tu veux faire ca sur plusieurs controle qui appelle la meme procedure afin de pas avoir à doubler le code

    Private Sub TextBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    call affiche_aide(keycode)
    End Sub
    Private Sub TextBox3_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    call affiche_aide(keycode)End Sub
    Private Sub TextBox4_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    call affiche_aide(keycode)
    End Sub

    sub affiche_aide(keycode as MSForms.ReturnInteger)

    if KeyCode = 113 then aide.show

    end sub
    3
  2. Invite05
     
    Super ! Ca fonctionne !
    Merci !
    0