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

vbOK 

OK button 

vbCancel 

Cancel button 

vbAbort 

Abort button 

vbRetry 

Retry button 

vbIgnore 

Ignore button 

vbYes 

Yes button 

vbNo 

No button 


Parameters

Description

Message$ 

This string value is the text that is shown in the message box. 

Type 

This numeric 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

vbOkOnly 

OK button 

vbOkCancel 

OK and Cancel buttons 

vbAbortRetryIgnore 

Abort, Retry, Ignore buttons 

vbYesNoCancel 

Yes, No, Cancel buttons 

vbYesNo 

Yes and No buttons 

vbRetryCancel 

Retry and Cancel buttons 


Icon

Value

Effect


No icon 

vbCritical 

16 

Stop icon 

vbQuestion 

32 

Question icon 

vbExclamation 

48 

Attention icon 

vbInformation 

64 

Information icon 


Default

Value

Effect

vbDefaultButton1 

First button 

vbDefaultButton2 

256 

Second button 

vbDefaultButton3 

512 

Third button 


Mode

Value

Effect

vbApplicationModal 

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