IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

bouton quitter dans userform dysfonctionne


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Mars 2013
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Mars 2013
    Messages : 35
    Par défaut bouton quitter dans userform dysfonctionne
    bonjour à toutes et tous,

    j'ai mis un bouton "quitter" dans un userform qui contient 3 combobox;

    Le bouton fonctionne bien mais uniquement lorsque toutes les combobox qui le precede sont remplies.

    Si rien n'est rempli dans la 1ere combobox, l'appui sur "Quitter" m'oblige à remplir la Combo 1, et ainsi de suite.

    Pour pourvoir quitter, je suis contraint d'appuyer 4 fois sur Quitter.....

    Je voudrai que le bouton "quitter" soit efficace quelque soit l’état de remplissage des combobox

    Quelqu'un aurait-il une idée ?

    A toutes fins utiles, voici le code.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    Option Compare Text
    Dim TblChoix2(), TblChoix3(), choix2(), choix1(), choix3()
    Private Sub UserForm_Initialize()
        choix1 = Application.Transpose(Range("Nom"))
        choix2 = Application.Transpose(Range("Prenom"))
        choix3 = Application.Transpose(Range("Employeur"))
        Set d1 = CreateObject("Scripting.Dictionary")
          For Each c In choix1: d1(c) = "": Next c
          Me.ComboBox1.List = d1.Keys
    End Sub
    Private Sub ComboBox1_Change()
       If Me.ComboBox1.ListIndex = -1 And IsError(Application.Match(Me.ComboBox1, choix1, 0)) Then
         Set d1 = CreateObject("Scripting.Dictionary")
         tmp = Me.ComboBox1 & "*"
         For Each c In choix1:
            If c Like tmp Then d1(c) = ""
         Next c
         Me.ComboBox1.List = d1.Keys
         Me.ComboBox1.DropDown
       Else
         Condition = Me.ComboBox1
         If Condition = "" Then Exit Sub
         Set d2 = CreateObject("Scripting.Dictionary")
         For i = LBound(choix2) To UBound(choix2)
           If choix1(i) = Condition Then d2(choix2(i)) = ""
         Next i
         TblChoix2 = d2.Keys
         Me.ComboBox2.List = TblChoix2
         Me.ComboBox2.SetFocus
         If Val(Application.Version) > 10 Then SendKeys "{f4}"
       End If
    End Sub
    Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
      If Me.ComboBox1.ListIndex = -1 Then Me.ComboBox1 = Me.ComboBox1.List(0)
    End Sub
    Private Sub ComboBox2_Change()
    If Me.ComboBox1 <> "" Then
      If Me.ComboBox2.ListIndex = -1 And IsError(Application.Match(Me.ComboBox2, choix2, 0)) Then
       Set d1 = CreateObject("Scripting.Dictionary")
       tmp = UCase(Me.ComboBox2) & "*"
       For Each c In TblChoix2
         If UCase(c) Like tmp Then d1(c) = ""
       Next c
       Me.ComboBox2.List = d1.Keys
       Me.ComboBox2.DropDown
      Else
        Set d3 = CreateObject("Scripting.Dictionary")
        Condition1 = Me.ComboBox1
        Condition2 = Me.ComboBox2
        If Condition1 = "" Or Condition2 = "" Then Exit Sub
         Set d3 = CreateObject("Scripting.Dictionary")
         For i = LBound(choix3) To UBound(choix3)
           If choix1(i) = Condition1 And choix2(i) = Condition2 Then d3(choix3(i)) = ""
         Next i
         TblChoix3 = d3.Keys
         Me.ComboBox3.List = TblChoix3
         Me.ComboBox3.SetFocus
         If Val(Application.Version) > 10 Then SendKeys "{f4}"
      End If
     End If
    End Sub
    Private Sub ComboBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
      If Me.ComboBox2.ListIndex = -1 Then Me.ComboBox2 = Me.ComboBox2.List(0)
    End Sub
    Private Sub ComboBox3_Change()
    If Me.ComboBox1 <> "" And Me.ComboBox2 <> "" Then
      If Me.ComboBox3.ListIndex = -1 And IsError(Application.Match(Me.ComboBox3, choix3, 0)) Then
       Set d1 = CreateObject("Scripting.Dictionary")
       tmp = UCase(Me.ComboBox3) & "*"
       For Each c In TblChoix3
         If c Like tmp Then d1(c) = ""
       Next c
       Me.ComboBox3.List = d1.Keys
       Me.ComboBox3.DropDown
      Else
        Condition1 = Me.ComboBox1
        Condition2 = Me.ComboBox2
        Condition3 = Me.ComboBox3
     
      End If
     End If
    End Sub
    Private Sub ComboBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
      If Me.ComboBox3.ListIndex = -1 Then Me.ComboBox3 = Me.ComboBox3.List(0)
    End Sub
    Private Sub CommandButton1_Click()
     If Me.ComboBox1 <> "" And Me.ComboBox2 <> "" Then
      ActiveCell = UCase(Me.ComboBox1)
      ActiveCell.Offset(, 1) = Me.ComboBox2
      ActiveCell.Offset(, 2) = Me.ComboBox3
      Unload Me
     Else
       MsgBox "Incomplet!"
       Exit Sub
     End If
    End Sub
     
    Private Sub CommandButton2_Click()
    Unload Me
    End Sub

  2. #2
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 84
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Bonjour
    Qu'est-ce-que c'est que cette histoire ?
    Supprime donc tes conditions dans l'évènement click pour n'y mettre que

  3. #3
    Membre averti
    Inscrit en
    Mars 2013
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Mars 2013
    Messages : 35
    Par défaut
    Citation Envoyé par unparia Voir le message
    Bonjour
    Qu'est-ce-que c'est que cette histoire ?
    Supprime donc tes conditions dans l'évènement click pour n'y mettre que
    c'est déjà le cas aux lignes 99 et suivantes....

  4. #4
    Expert éminent
    Avatar de Marc-L
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2013
    Messages
    9 468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2013
    Messages : 9 468
    Par défaut
    Bonjour,

    bon ben alors place un point d'arrêt dans chaque procédure de ton code, tu comprendras mieux alors !

    ___________________________________________________________________________________________________________
    Je suis Paris, Egypte, Nigeria, New-York, Mogadicio, Barcelone, London, Manchester, Stockholm, Istanbul, Berlin, Nice, Bruxelles, Charlie, …

  5. #5
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 84
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Oui ? et alors ? -->> clique donc sur l'autre bouton !

  6. #6
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 374
    Billets dans le blog
    8
    Par défaut re
    bonjour
    si avec unload me il se ferme pas je soupconne une limite whitescreen attention!!!
    met des espions pour voir quand tu fait riensi il ny a pas quelque chose qui tourne en rond (une bascule entre deux partie du code) par exemple
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

  7. #7
    Membre Expert
    Inscrit en
    Octobre 2010
    Messages
    1 401
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 401
    Par défaut
    Met un drapeau dans l'evenement "UserForm_QueryClose" pour que les evenements ComboBox1_Exit, ComboBox2_Exit, etc... ne s'executent pas.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    Dim NePasExecuterExit
     
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
     NePasExecuterExit = True
    End Sub
     
    Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If NePasExecuterExit = True Then Exit Sub
      If Me.ComboBox1.ListIndex = -1 Then Me.ComboBox1 = Me.ComboBox1.List(0)
    End Sub

  8. #8
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Avril 2016
    Messages
    7 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 84
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Avril 2016
    Messages : 7 563
    Par défaut
    Bonjour
    si avec unload me il se ferme pas je soupconne une limite whitescreen attention!!!
    ou plus simplement une instruction contradictoire dans l'évènement queryclose

Discussions similaires

  1. Obtenir le dernier bouton cliqué dans userform
    Par modenofx dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 24/11/2011, 19h35
  2. [XL-2003] bouton cancel dans userform
    Par yvespi dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 30/07/2010, 11h18
  3. [XL-2007] Bouton toupie dans userform
    Par dodo28 dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 04/01/2010, 17h35
  4. vba ajout de bouton dynamique dans userform + action sur bouton ajouté
    Par choupette_64 dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 29/07/2009, 15h04
  5. Bouton "quitter" dans une forme vb6
    Par lebienestrare dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 07/09/2006, 17h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo