Excel VBA MsgBox basics.
MsgBox Function
Displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked.
Syntax
context | Description |
---|---|
prompt | a (Must) string, The maximum length of prompt is approximately 1024 characters, If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13) |
buttons | Optional, the sum of values specifying the number and type of buttons to display, the default value for buttons is 0. |
title | Optional. String expression displayed in the title bar of the dialog box. |
helpfile | Optional. String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box. |
context | Optional. Numeric expression that is the Help context number assigned to the appropriate Help topic by the Help author. |
Examples
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 |
Example
in this example if you choose "Yes" then the active cell will be erased.