XL 2021 Mise en forme MsgBox

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 !

Constantin

XLDnaute Occasionnel
Supporter XLD
Bonjour à tous,
J'essaye en vain de pouvoir "améliorer" mes MsgBox. Sujet déjà évoqué sur XLD mais solutions que je n'arrive pas à comprendre (je sais, je ne suis pas bon...)
J'aimerai donc, à minima, pouvoir mettre en gras certaines informations de mes MsgBox. Il faudrait passer par des UserForms...
En gros, pour aller chercher ma baguette à 50 mètres de chez moi, il faudrait que je passe par New York ?
J'ai fait toutes les recherches sur le Web pour résoudre ce problème. La solution présentée sur XLD est bien appétissante mais je n'y arrive pas (je ne maitrise pas du tout les UserForms)...
Au cazou, je vous joint un fichier anonymisé et les messages (codes) que je voudrais voir apparaître autrement (en gras ou en rouge ou les deux...).

Sub Macro2()
Call SauvegardeAutomatique
Dim L%, Rep$, Ligne%, DL%, Nom$, Prénom$
On Error GoTo FinR
With Sheets("base de données")
L = Selection.Row ' Ligne sélectionnée
Nom = Cells(L, "K"): Prénom = Cells(L, "L")
If Nom = "" Or Prénom = "" Then MsgBox "Sélectionnez un nom valide en colonne Nom de la feuille departs.": Exit Sub ' Verif si ligne valide
Rep = MsgBox("Voulez vous effacer les données " & L & " concernant " & Nom & " " & Prénom & " ?" & _
Chr(10) & "Dans la base de données.", vbExclamation + vbYesNo, "Demande de confirmation.")
If Rep = vbNo Then Exit Sub
DL = .Cells(Rows.Count, "E").End(xlUp).Row ' recherche dernière ligne des noms dans base de données
Application.EnableEvents = False
For Ligne = 4 To DL ' on parcourt toutes les lignes
If .Cells(Ligne, "E") = Nom And .Cells(Ligne, "F") = Prénom Then ' si Nom et Prénom trouvés, on efface
Range(.Cells(Ligne, "E"), .Cells(Ligne, "AA")).ClearContents
Application.EnableEvents = True
Exit Sub
End If
Next Ligne
End With
FinR:
Application.EnableEvents = True
MsgBox "Ligne sélectionnée effacée ", vbOKOnly + vbInformation, "Pour information"
End Sub
Bien cordialement,
 

Pièces jointes

Solution
Mes tentatives :
- installer les 2 lignes
Sheets("base de données").Select
Range("E4").Select

dans une autre macro (j'ai pris "sauvegarde automatique" au hasard). Cela fonctionne.
- Modifier les paramètres de sécurité : aucune effet
- MsgBox "Ligne sélectionnée effacée ", vbOKOnly + vbInformation, "Pour information" ne s'affiche plus en fin de macro...
A chaque jour suffit sa peine, bonne nuit (au cas où je ferais un rêve qui me donne la solution)
Mes tentatives :
- installer les 2 lignes
Sheets("base de données").Select
Range("E4").Select

dans une autre macro (j'ai pris "sauvegarde automatique" au hasard). Cela fonctionne.
- Modifier les paramètres de sécurité : aucune effet
- MsgBox "Ligne sélectionnée effacée ", vbOKOnly + vbInformation, "Pour information" ne s'affiche plus en fin de macro...
A chaque jour suffit sa peine, bonne nuit (au cas où je ferais un rêve qui me donne la solution)
 
Mes tentatives :
- installer les 2 lignes
Sheets("base de données").Select
Range("E4").Select

dans une autre macro (j'ai pris "sauvegarde automatique" au hasard). Cela fonctionne.
- Modifier les paramètres de sécurité : aucune effet
- MsgBox "Ligne sélectionnée effacée ", vbOKOnly + vbInformation, "Pour information" ne s'affiche plus en fin de macro...
A chaque jour suffit sa peine, bonne nuit (au cas où je ferais un rêve qui me donne la solution)
bonjour,
Ce message est défi comme étant la solution et je vois pas en quoi il satisfait la demande initiale !
 
Bonjour,
Je ne savais pas comment clore cette discussion bien que la solution n'ait pas été trouvée à ce moment. De plus, cette discussion s'étendait sur trois pages et devenait un peu longue, d'où cette clôture un peu inhabituelle... Quand il y a trois pages d'échanges, il devient difficile de s'y retrouver
Avec toutes mes excuses si cela t'as "choqué".
 
Salut,
avec un userform + 1 activeX WebBrowser on peut faire tout en HTML ( les boutons aussi) :
Exemple de code d'appel :
VB:
Sub TestPopup()
Dim Nom As String, Prénom As String, Msg As String, Titre As String
Dim rep As VbMsgBoxResult
Nom = "Manvussat"
Prénom = "Gérard"
Titre = "<span style='color:red;'><b> Demande de Confirmation</span></b>" ' Titre en rouge, en gras
Msg = "Voulez vous effacer les données concernant <b>" & Prénom & " " & Nom & "</b> " & _
      "<br> dans la base de données ?" ' Nom et Prénom en gras
MsgBoxHtml.ShowMsg Msg, Titre, "question", vbYesNo, 450, 200 'icone question , largeur usf 450, hauteur 200
rep = MsgBoxHtml.Resultat
Select Case rep
    Case vbYes: MsgBox "Vous avez choisi OUI"
    Case vbNo: MsgBox "Vous avez choisi NON"
    Case vbCancel: MsgBox "Annulé"
End Select
End Sub

MsgBoxHtml.gif


Nullosse
 
bonjour,
 
Plus explicite ?
Tu veux dire plus simple ? Ca me parait difficile de faire plus simple en ayant la possibilité de définir tailles / couleurs / position.
Si tu sais faire un MsgBox, tu sais faire un Msg.Box.
VB:
MsgBox Message, Boutons (ex vbOkCancel), Titre
Msg.Box Message, Boutons (ex vbOkCancel), Titre
Si tu veux mettre le texte en gras tu fais:
VB:
Msg.SetPromptFontStyle "BOLD"
Msg.Box Message, Boutons (ex vbOkCancel), Titre


Sinon le code contient en tête ces commentaires (certes en anglais mais google traduction peut les franciser):
VB:
#Const LANGUAGE = "FR"
'#Const LANGUAGE = "EN"
'
'Set to True for an attempt to correct the external UserForm margins for a precise visual position (depends on Windows/Office versions)
#Const CORRECT_USERFORM_MARGINS = True

'----------------------
'Custom MsgBox Function
'----------------------
'
'---------------
'Calling Msg.Box
'---------------
'<> Strictly equivalent to a standard MsgBox for button values from 0 to 768 (except helpfile & context parameters).
'   See https://docs.microsoft.com/fr-fr/office/vba/language/reference/user-interface-help/msgbox-function
'
'   Dim ReturnValue As Integer
'   ReturnValue = Msg.Box(Prompt, Buttons, Title)
'
'<> One more parameter has been added in order to manage the Control + Break input and have a return code -1 that
'   can be used to stop the code and debug after the Msg.Box call to simulate a Control + Break on a standard MsgBox.
'
'   Dim ReturnValue As Integer
'   ReturnValue = Msg.Box(Prompt, Buttons, Title, ReturnBreak:=True)
'   If ReturnValue = -1 Then Stop
'
'-------------------------------
'Calling set parameter functions
'-------------------------------
'<> They must be called before the Msg.Box() function.
'   Their names are self explanatory.
'   The settings are volatile and only applicable to the next Msg.Box() function call.
'
'<> Prompt parameters settings:
'   --------------------------
'   With Msg
'       .SetPromptFontName(FontName As String)
'       .SetPromptFontSize(FontSize As Integer)
'       .SetPromptFontStyle(FontStyle As String)
'       .SetPromptFontColor(FontColor As Long)
'       .SetPromptBackColor(BackColor As Long)
'       .SetPromptTextAlign(TextAlign As Integer)   'fmTextAlignLeft, fmTextAlignCenter, fmTextAlignRight
'   End With
'
'<> Button parameters settings:
'   --------------------------
'   TabButtonValues: Nothing for all buttons, button value(s) (vbOK, vbCancel, vbAbort, vbRetry, vbIgnore, vbYes, vbNo) separated by commas
'   Example 1: Msg.SetButtonFontSize 20 (all buttons to be set a Font Size of 20)
'   Example 2: Msg.SetButtonBackColor vbRed, vbNo, vbCancel (button <No> and button <Cancel> to be set a red background)
'
'   With Msg
'       .SetButtonMinWidth(Width As Double)
'       .SetButtonMinHeight(Height As Double)
'       .SetButtonFontName(FontName As String, ParamArray TabButtonValues() As Variant)
'       .SetButtonFontSize As Integer, ParamArray TabButtonValues() As Variant
'       .SetButtonFontStyle(FontStyle As String, ParamArray TabButtonValues() As Variant)
'       .SetButtonFontColor(FontColor As Long, ParamArray TabButtonValues() As Variant)
'       .SetButtonBackColor(Color As Long, ParamArray TabButtonValues() As Variant)
'   End With
'
'<> UserForm position parameters settings:
'   -------------------------------------
'   By default the UserForm is screen centered like the standard MsgBox and is displayed to fit into the screen.
'   Example 1: Msg.SetPositionXY 100, 200
'   Example 2: Msg.SetPositionXY 100, 200, HorizontalShiftPoints:=Msg.FinalWidth(-0.5), VerticalShiftPoints:=Msg.FinalHeight(-0.5)
'   Example 3: Msg.SetPositionOnWorksheetObject ActiveSheet.[H10]
'   Example 4: Msg.SetPositionOnWorksheetObject ActiveSheet.Shapes(1), HorizontalShiftPoints:=ActiveSheet.Shapes(1).Width
'   Example 5: Msg.SetPositionOnWorksheetObject ActiveSheet.Shapes(1), HorizontalShiftPoints:=Msg.FinalWidth(-1)
'   Example 6: Msg.SetFitToScreen False (Default is True)
'
'   With Msg
'       .FinalWidth(Ratio As Single) The shift will be based on the final message Width * Ratio
'       .FinalHeight(Ratio As Single) The shift will be based on the final message Height * Ratio
'
'   For WINDOWS:
'       .SetPositionXY(LeftPoints As Double, TopPoints As Double, _
'                      Optional HorizontalShiftPoints As Double = 0, _
'                      Optional VerticalShiftPoints As Double = 0))

'       .SetPositionOnWorksheetObject(WorksheetObject As Object, _
'                                     Optional HorizontalShiftPoints As Double = 0, _
'                                     Optional VerticalShiftPoints As Double = 0))
'
'       .SetFitToScreen(FitToScreen as Boolean) (Default is True)
'
'   For MAC/OS:
'       .SetPositionXY(LeftPixels As Long, TopPixels As Long, _
'                      Optional HorizontalShiftPixels As Long = 0, _
'                      Optional VerticalShiftPixels As Long = 0))
'
'       .SetPositionOnWorksheetObject(WorksheetObject As Object, _
'                                     Optional HorizontalShiftPixels As Long = 0, _
'                                     Optional VerticalShiftPixels As Long = 0))
'
'       .SetFitToScreen(FitToScreen as Boolean)  (Default is True)
'   End With
'
'<> UserForm Show Mode:
'   ------------------
'   By default, the UserForm is shown vbModal, like a MsgBox.
'   But it's possible to show it vbModeless in case an interaction with the Workbook / Worksheet is needed before a
'   button is clicked. For example a selection.
'
'   With Msg
'       .SetShowMode(ShowMode As Integer)
'   End With
'
'   Example: Msg.SetShowMode vbModeless
'
'-------
'Buttons
'-------
'Constant           Value   Description
'vbOKOnly           0       Display OK button only.
'vbOKCancel         1       Display OK and Cancel buttons.
'vbAbortRetryIgnore 2       Display Abort, Retry, and Ignore buttons.
'vbYesNoCancel      3       Display Yes, No, and Cancel buttons.
'vbYesNo            4       Display Yes and No buttons.
'vbRetryCancel      5       Display Retry and Cancel buttons.
'vbCritical         16      Display Critical Message icon.
'vbQuestion         32      Display Warning Query icon.
'vbExclamation      48      Display Warning Message icon.
'vbInformation      64      Display Information Message icon.
'vbDefaultButton1   0       First button is default.
'vbDefaultButton2   256     Second button is default.
'vbDefaultButton3   512     Third button is default.
'vbDefaultButton4   768     Fourth button is default.
'vbApplicationModal 0       Application modal; the user must respond to the message box before continuing work in the current application.
'----------------
'NOT USED/TREATED except vbMsgBoxRight, equivalent to a Msg.SetPromptTextAlign(fmTextAlignRight)
'----------------
'vbSystemModal          4096    System modal; all applications are suspended until the user responds to the message box.
'vbMsgBoxHelpButton     16384   Adds Help button to the message box.
'vbMsgBoxSetForeground  65536   Specifies the message box window as the foreground window.
'vbMsgBoxRight          524288  Text is right-aligned.
'vbMsgBoxRtlReading     1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems.
'
'-------------
'Return values
'-------------
'Constant           Value   Description
'vbOK               1       OK
'vbCancel           2       Cancel
'vbAbort            3       Abort
'vbRetry            4       Retry
'vbIgnore           5       Ignore
'vbYes              6       Yes
'vbNo               7       No
'UserForm closed or Escape  If vbOKOnly -> vbOK
'                           If vbOKCancel or vbYesNoCancel or vbRetryCancel -> vbCancel
'                           Otherwise not allowed
'-----------------------------
 
Après si tu sais causer HTML, la solution de @nullosse est pas mal non plus.
L'avantage du Msg.Box c'est qu'il garantit laffichage de l'intégralité du message alors que MsgBox tronque à partir d'une certaine longueur.
Tu n'aurais pas un fichier de démo à m'envoyer pour comprendre où et comment installer tous ces codes ? Rien ne vaut le visuel,
A bientôt ?
 
- 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
4
Affichages
632
  • Question Question
XL 2021 VBA excel
Réponses
4
Affichages
433
Réponses
5
Affichages
848
Réponses
2
Affichages
485
Retour