Search code examples
vbaexcelmsgbox

Is it possible to have VBA MsgBox as type vbYesNo and vbExclamation simultaneously?


I am trying to get a message box in vba to display as a regular yes no box:

vbYesNo MsgBox

But with the Exclamation icon as well:

vbExclamation MsgBox

I can do either easily by vba. Like the vbExclamation version code below:

MsgBox "Are you sure you want to continue?", vbExclamation, "Warning!"

or the version for the vbYesNo:

Dim msgboxResult As VbMsgBoxResult
msgboxResult = MsgBox("Are you sure you want to continue?", vbYesNo, "Warning!")
If msgboxResult = vbNo Then Exit Sub

But am not sure if the two can be combined?

On the MSDN vba refrence for the MsgBox function, https://msdn.microsoft.com/en-us/library/aa445082(v=vs.60).aspx it does say at the very bottom the following:

"Note: To specify more than the first named argument, you must use MsgBox in an expression. To omit some positional arguments, you must include the corresponding comma delimiter."

Is this referring to what I need, and if so, how would I implement this please?


Solution

  • I think

    msgboxResult = MsgBox("Are you sure you want to continue?", vbExclamation + vbYesNo, "Warning!")
    

    would do it the way you want to have.