Nombre de MsgBox s'étant ouvertes

Résolu
Yoyo01000 Messages postés 1720 Date d'inscription   Statut Membre Dernière intervention   -  
Yoyo01000 Messages postés 1720 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
J'aimerais savoir s'il était possible de compter le nombre de MsgBox qui s'ouvrent lors de l’exécution d'une macro (après clic sur un CommandButton) ?

Configuration: Windows / Chrome 85.0.4183.121


--
Pensez au "merci" et au "résolu" quand le sujet l'est.

4 réponses

  1. via55 Messages postés 14393 Date d'inscription   Statut Membre Dernière intervention   2 759
     
    Bonjour Yoyo

    Tu peux dans les lignes de macros mettre un code après chaque instruction Msgbox pour incrémenter une variable et faire en fin de macro afficher cette variable dans une dernière Msgbox!

    Cdlmnt
    Via
    0
  2. Yoyo01000 Messages postés 1720 Date d'inscription   Statut Membre Dernière intervention   168
     
    Bonjour via55 et merci pour ta réponse !

    En fait, mon intérêt, est d'exécuter la suppression d'une feuille (crée par cette macro), si <2 MsgBox s'ouvre.

    Je pensais pouvoir compter chaque ouverture de MsgBox ou alors avoir un compteur qui, en fin d'exécution de macro, me donne le nombre de MsgBox s'étant ouvertes.

    Peut-être que ça n'est pas réalisable et je pense déjà à un contournement !
    0
  3. via55 Messages postés 14393 Date d'inscription   Statut Membre Dernière intervention   2 759
     
    Re

    Je ne comprends pas tout

    Tu as une macro qui crée une feuille et si lors de l'exécution de la macro moins de Msgbox s'ouvrent tu voudrais supprimer la feuille ?
    Tu peux parfaitement compter les ouvertures comme j'indiquais dans mon précédent post

    Quel est le code de ta macro ?
    0
    1. Yoyo01000 Messages postés 1720 Date d'inscription   Statut Membre Dernière intervention   168
       
      Alors en fait, si certaines zones du formulaire ne sont pas remplies, une MsgBox s'ouvre pour prévenir.
      Une fois celle-ci validée par OK, ça efface la feuille qui venait d'être crée.
      Par contre, à partir de 2 zones non remplies, la feuille crée est supprimée par le 1er OK de la MsgBox et ensuite, le dernier onglet du classeur est aussi supprimé après le OK de la 2ème MsgBox et c'est là que ça ne va pas.

      J'ai pensé à la solution d'obligation de saisir 1 par 1 les zones du formulaire, dans un ordre précis et si ça n'est pas fait, impossible de saisir la zone d'après (par exemple zone 1 non remplie = impossible de remplir la zone 2)

      Voici mon code :

      Private Sub CommandButton_Valider_Click()
      
      'Générer une fiche avec son n° d'ID
      Dim feuille As String
      'Nom de l'onglet
      feuille = Me.TextBox_N°ICP.Text & "-ST" & Me.ComboBox_ST.Value
      'On met en marche la gestion des erreurs
      On Error Resume Next
      'On active la feuille générée
      Sheets(feuille).Activate
      If Err > 1 Then ' la feuille n'existe pas on la crée
      Sheets.Add after:=Sheets(Sheets.count)
      ActiveSheet.Name = feuille
      'Elle existe
      Else
      'On la supprime
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      'On en crée une nouvelle qui porte le nom choisi
      Sheets.Add after:=Sheets(Sheets.count)
      ActiveSheet.Name = feuille
      End If
      ' on arrête la gestion des erreurs
      On Error GoTo 0
      
      'Affichage de la feuille "VIERGE"
      Sheets("VIERGE").Visible = True
      
      'On copie une fiche vierge
      With Sheets("VIERGE").Select
      Cells.Select
      Application.CutCopyMode = False
      Selection.Copy
      'Sélection du dernier onglet à droite
      Sheets(Sheets.count).Select
      Range("A1").Select
      Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
      SkipBlanks:=False, Transpose:=False
      ActiveSheet.Paste
      ActiveWindow.Zoom = 70
      Range("A1").Select
      Application.CutCopyMode = False
      End With
      
      'Insertion de l'auteur :
      If ComboBox_Noms_Prénoms.Value = "" Then
      MsgBox "Champ [Auteur] obligatoire", vbExclamation
      ComboBox_Noms_Prénoms.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      Range("E4").Value = ComboBox_Noms_Prénoms.Value
      End If
      
      'Insertion de la date :
      If TextBox_Date.Value = "" Then
      MsgBox "Champ [Date] au format 00/00/0000 obligatoire", vbExclamation
      TextBox_Date.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      Range("P4").Value = TextBox_Date.Value
      End If
      
      'Insertion du numéro d'ID Bottom Up
      If TextBox_N°ICP.Value = "" Then
      MsgBox "Champ [ID B-U] obligatoire", vbExclamation
      TextBox_N°ICP.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      Range("W4").Value = TextBox_N°ICP.Value
      End If
      
      'Insertion du n° de ST :
      If ComboBox_ST.Value = "" Then
      MsgBox "N° de la Small Team non renseigné", vbExclamation
      ComboBox_ST.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      Range("Q6").Value = ComboBox_ST.Value
      End If
      
      'Insertion de la déscription de l'ICP :
      If TextBox_Déscription_ICP.Value = "" Then
      MsgBox "Champ [Déscription de l'ICP] obligatoire", vbExclamation
      TextBox_Déscription_ICP.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      Range("B8").Value = TextBox_Déscription_ICP.Value
      End If
      
      'Insertion du résultat escompté :
      If OptionButton_Sécurité_Ergonomie = False And _
      OptionButton_Coût = False And _
      OptionButton_Qualité = False And _
      OptionButton_Délai = False And _
      OptionButton_Environnement = False And _
      OptionButton_Propreté_Rangement = False Then
      MsgBox "Bouton du résultat escompté non coché", vbExclamation
      OptionButton_Sécurité_Ergonomie.BackColor = RGB(255, 97, 97)
      OptionButton_Coût.BackColor = RGB(255, 97, 97)
      OptionButton_Qualité.BackColor = RGB(255, 97, 97)
      OptionButton_Délai.BackColor = RGB(255, 97, 97)
      OptionButton_Environnement.BackColor = RGB(255, 97, 97)
      OptionButton_Propreté_Rangement.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      If OptionButton_Sécurité_Ergonomie = True Then
      Range("B18").Value = "Sécurité - Ergonomie"
      End If
      If OptionButton_Coût = True Then
      Range("B18").Value = "Coût"
      End If
      If OptionButton_Qualité = True Then
      Range("B18").Value = "Qualité"
      End If
      If OptionButton_Délai = True Then
      Range("B18").Value = "Délai"
      End If
      If OptionButton_Environnement = True Then
      Range("B18").Value = "Environnement"
      End If
      If OptionButton_Propreté_Rangement = True Then
      Range("B18").Value = "Propreté - Rangement"
      End If
      End If
      
      'Insertion de la solution proposée
      If TextBox_Solution_Proposée <> "" Then
      Range("B21").Value = TextBox_Solution_Proposée.Value
      End If
      
      'Insertion de la validation
      If CheckBox_OUI = True Then
      Range("G30").Value = "X"
      End If
      
      If CheckBox_NON = True Then
      Range("L30").Value = "X"
      End If
      
      If CheckBox_OUI = True And _
      CheckBox_NON = True Then
      MsgBox "L'accord est soit OUI soit NON", vbExclamation
      End If
      
      If CheckBox_OUI = False And _
      CheckBox_NON = False Then
      MsgBox "Champ [Accord] non renseigné", vbExclamation
      CheckBox_OUI.BackColor = RGB(255, 97, 97)
      CheckBox_NON.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      If CheckBox_NON = True And _
      TextBox_NON_Pourquoi.Value = "" And _
      CheckBox_OUI = False Then
      MsgBox "Merci de remplir le pourquoi du refus de l'ICP", vbExclamation
      TextBox_NON_Pourquoi.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      End If
      End If
      
      If TextBox_NON_Pourquoi <> "" And _
      CheckBox_OUI = True Then
      MsgBox "L'ICP est accordée, il n'y a donc pas de raison à son refus", vbExclamation
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      Range("E31").Value = TextBox_NON_Pourquoi.Value
      End If
      
      'Insertion de la date
      If ComboBox_day.Value = "" Then
      MsgBox "merci de remplir le jour de prise en compte de l'accord ou du refus", vbExclamation
      ComboBox_day.BackColor = RGB(255, 97, 97)
      
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      Range("S29").Value = ComboBox_day.Value
      
      Range("X29").Value = TextBox_year
      End If
      
      If ComboBox_month.Value = "" Then
      MsgBox "merci de remplir le mois de prise en compte de l'accord ou du refus", vbExclamation
      
      ComboBox_month.BackColor = RGB(255, 97, 97)
      Application.DisplayAlerts = False
      ActiveSheet.Delete
      Application.DisplayAlerts = True
      Else
      
      Range("V29").Value = ComboBox_month.Value
      Range("X29").Value = TextBox_year
      End If
      
      
      'Insertion du calcul 1
      If TextBox_Calcul_1.Value <> "" Then
      Range("H33").Value = TextBox_Calcul_1.Value
      End If
      
      'insertion du calcul 2
      If TextBox_Calcul_2.Value <> "" Then
      Range("K33").Value = TextBox_Calcul_2.Value
      End If
      
      'Insertion du calcul 3
      If TextBox_Calcul_3.Value <> "" Then
      Range("N33").Value = TextBox_Calcul_3.Value
      End If
      
      'Insertion du résultat des 3 calculs :
      If TextBox_Calcul_1.Value = "" And _
      TextBox_Calcul_2.Value = "" And _
      TextBox_Calcul_3.Value = "" Then
      Exit Sub
      Else
      
      If TextBox_Calcul_1.Value <> "0" And _
      TextBox_Calcul_2.Value <> "0" And _
      TextBox_Calcul_3.Value <> "0" Then
      Range("Q33").Value = TextBox_Calcul_1.Value * _
      TextBox_Calcul_2.Value * _
      TextBox_Calcul_3.Value
      Else
      
      If TextBox_Calcul_1.Value = "0" And _
      TextBox_Calcul_2.Value <> "0" And _
      TextBox_Calcul_3.Value <> "0" Then
      Range("Q33").Value = TextBox_Calcul_2.Value * _
      TextBox_Calcul_3.Value
      End If
      End If
      End If
      
      'Masquer la feuille "VIERGE"
      Sheets("VIERGE").Visible = False
          
      'Sélection de la dernière feuille de droite
      Sheets(Sheets.count).Select
      
      End Sub


      Le fichier : https://www.cjoint.com/c/JIzooAISQAR
      0
  4. via55 Messages postés 14393 Date d'inscription   Statut Membre Dernière intervention   2 759
     
    Oui ta solution de saisir un par un les zones du formulaires est sans doute meilleure
    Tu peux aussi passer par un userform dans lequel les zones suivantes à saisir sont masquées tant que la précédente n'est pas complète
    0
    1. Yoyo01000 Messages postés 1720 Date d'inscription   Statut Membre Dernière intervention   168
       
      Merci via55, je vais me pencher sur cette solution ;-)
      0