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

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

 

 

Parameter

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

1

OK button

vbOkCancel

2

OK and Cancel buttons

vbAbortRetryIgnore

3

Abort, Retry, Ignore buttons

vbYesNoCancel

4

Yes, No, Cancel buttons

vbYesNo

5

Yes and No buttons

vbRetryCancel

6

Retry and Cancel buttons

 

 

Icon

Value

Effect

 

0

No icon

vbCritical

16

Stop icon

vbQuestion

3

Question icon

vbExclamation

4

Attention icon

vbInformation

5

Information icon

 

 

Default

Value

Effect

vbDefaultButton1

0

First button

vbDefaultButton2

256

Second button

vbDefaultButton3

512

Third button

 

 

Default

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