I would like to know if it's possile to show a Msgbox in VBA (Excel 2007), without any button being set as default? I have a yes\no button and I don't want the user to hit return or the space bar and accidentally trigger a default button.
Anyone know if this is possible so that neither button on my form is set to default, forcing the user to click yes or no?
If MsgBox("Message goes here", vbYesNo + vbQuestion ) = vbYes Then
'Something
Else
'Else
End If
Another workaround (other than a UserForm, or trapping Enter & Space etc) is to
code
Dim lngMsg As Long
Do
lngMsg = MsgBox("Message goes here (Yes or No)", vbQuestion + vbYesNoCancel + vbDefaultButton3)
Loop While lngMsg = vbCancel
If lngMsg = vbYes Then
' route a
Else
' route b
End If
No this is not possible unfortunately.
A (not particularly nice) workaround would be to code the message box using a UserForm. Probably not worth doing given the benefit over the extra code you'd have to maintain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With