MsgBox function

MsgBox enables you to display a dialog box with a message inside it, with optional buttons such as OK and Cancel.

MsgBox arguments

MsgBox "Message",options,title
The first argument is the message to be displayed. The second (optional) controls the appearance and behaviour of the dialog box, and the third (also optional) specifies the text to be placed in the title bar of the dialog box.

Button options

These control which buttons are displayed.
vbOKOnly                OK
vbOKCancel              OK, Cancel
vbYesNoCancel           Yes, No, Cancel
vbYesNo                 Yes, No

Icon options

These control what icon is displayed with the text and buttons.
vbCritical              Stop
vbQuestion              Question mark
vbExclamation           Exclamation point
vbInformation           Information

Default button options

vbDefaultButton1        1st button is default
vbDefaultButton2        2nd button is default
vbDefaultButton3        3rd button is default
vbDefaultButton4        4th button is default

Returned values

vbOK                    OK
vbCancel                Cancel
vbYes                   Yes
vbNo                    No

Examples

MsgBox "Click OK to continue"

MsgBox "Fatal Error", vbCritical
MsgBox "Click Yes to continue, No to stop", vbQuestion + vbYesNo
MsgBox "Click Yes to continue, No to stop", vbQuestion+vbDefaultButton2+vbYesNo
MsgBox "Program hasn't worked", vbExclamation
MsgBox "Program ran successfully", vbInformation, "All singing all Dancing program Version 1.3"