Chapter 5 – MsgBox and InputBox
MsgBox
Msgbox function is used to show an alert or message to user in form of dialog box. This function is normally used to show confirmation of the action taken or take inputs from user in form of yes or no.

Commonly used Buttons in MsgBox:
Button Type | Value | Description |
vbOKOnly | 0 | Displays OK button |
vbOKCancel | 1 | Displays OK and Cancel buttons |
vbAbortRetryIgnore | 2 | Displays Abort, Retry and Ignore buttons |
vbYesNoCancel | 3 | Displays Yes, No and Cancel buttons |
vbYesNo | 4 | Displays Yes and No buttons |
vbRetryCancel | 5 | Displays Retry and Cancel buttons |
vbCritical | 16 | Displays Critical Message icon |
vbExclamation | 48 | Displays Warning Message icon |
vbInformation | 64 | Displays Information Message icon |
Example 1: A normal message box
Code:
MsgBox ("World is beautiful")
Result:
Example 2: Message box with Yes and No buttons
Code:
MsgBox "Are you sure?", vbYesNo
Result:
Example 3: Message box with Title
Code:
MsgBox "Are you sure?", vbYesNo, "Confirmation"
Result:
Example 4: Message box with Information Message Icon
Code:
MsgBox "Task is completed", vbInformation, "Confirmation"
Result:
Example 5: Message box with Critical Message Icon
Code:
MsgBox "Task could not be completed", vbCritical, "Error"
Result:
Example 6: Message box with Abort, Retry and Ignore buttons
Code:
MsgBox "Task could not be completed" & vbNewLine & "Want to retry?", vbAbortRetryIgnore, "Error"
Result:
Displays a dialog box to accept input from user. This function is normally used to take simple input from user in form of string.
InputBox

Example 1: Simple Input dialog box
Code:
InputBox ("What is your name?")
Result:
Example 2: Input box with title and default value
Code:
InputBox "How many sheets to be added?", "Sheets", 3
Result: