MsgBox Instruction/Function
Syntax
MsgBox Message$[, Type][, Title$]
-or-
MsgBox(Message$[, Type][, Title$])
Group
Description
Show a message box titled Title$. Type controls what the message box looks like (choose one value from each category). Use MsgBox( ) if you need to know what button was pressed. The result indicates which button was pressed.
Result |
Value |
Button Pressed |
vbOK |
1 |
OK button |
vbCancel |
2 |
Cancel button |
vbAbort |
3 |
Abort button |
vbRetry |
4 |
Retry button |
vbIgnore |
5 |
Ignore button |
vbYes |
6 |
Yes button |
vbNo |
7 |
No button |
Parameters |
Description |
This string value is the text that is shown in the message box. |
|
This numeric value controls the type of message box. Choose one value from each of the following tables. |
|
This string value is the title of the message box. |
Button |
Value |
Effect |
vbOkOnly |
0 |
OK button |
vbOkCancel |
1 |
OK and Cancel buttons |
vbAbortRetryIgnore |
2 |
Abort, Retry, Ignore buttons |
vbYesNoCancel |
3 |
Yes, No, Cancel buttons |
vbYesNo |
4 |
Yes and No buttons |
vbRetryCancel |
5 |
Retry and Cancel buttons |
Icon |
Value |
Effect |
0 |
No icon |
|
vbCritical |
16 |
Stop icon |
vbQuestion |
32 |
Question icon |
vbExclamation |
48 |
Attention icon |
vbInformation |
64 |
Information icon |
Default |
Value |
Effect |
vbDefaultButton1 |
0 |
First button |
vbDefaultButton2 |
256 |
Second button |
vbDefaultButton3 |
512 |
Third button |
Mode |
Value |
Effect |
vbApplicationModal |
0 |
Application modal |
vbSystemModal |
4096 |
System modal |
vbMsgBoxSetForeground |
&h10000 |
Show message box in front of all other windows |
Example
Sub Main
MsgBox "Please press OK button"
If MsgBox("Please press OK button",vbOkCancel) = vbOK Then
Debug.Print "OK was pressed"
Else
Debug.Print "Cancel was pressed"
End If
End Sub