MsgBox Instruction/Function

Syntax

MsgBox Message$[, Type][, Title$]
-or-
MsgBox(Message$[, Type][, Title$])

Group

User Input

Description

Shows a message box titled Title$. Type controls what the message box looks like (select one value from each category). Use MsgBox( ) if you need to know what button is pressed. The result indicates which button is pressed.

Parameters

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
Message$ This string value is the text that is shown in the message.
Type This numeric value controls the type of message. Select one value from each of the following tables.
Title$ This string value is the title of the message.

 

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 Shows the message 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