MsgBox Instruction/Function
Syntax:
MsgBox Message$[, Type][,
Title$]
-or-
MsgBox(Message$[, Type][,
Title$])
Group:
User Input
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
- bOK 1 OK button
- bCancel 2 Cancel button
- bAbort 3 Abort button
- bRetry 4 Retry button
- bIgnore 5 Ignore button
- bYes 6 Yes button
- bNo 7 No button
Parameter Description
Message$
This string value is the text that is shown in the message box.
Type This
number value controls the type of message box. Choose one value from each
of the following tables.
Title$
This string value is the title of the message box.
Button
Value Effect
- bOkOnly 0 OK button
- bOkCancel 1 OK and Cancel buttons
- bAbortRetryIgnore
- Abort, Retry, Ignore buttons
- Yes, No, Cancel buttons
- bYesNo 4 Yes and No buttons
- bRetryCancel 5 Retry and Cancel buttons
Icon Value Effect
0 No icon
- bCritical 16 Stop icon
- bQuestion 32 Question icon
- bExclamation 48 Attention icon
- bInformation 64 Information icon
Default Value Effect
- First button
- Second button
- Third button
Mode Value Effect
- Application modal
- System modal
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