O'Reilly logo

VB & VBA in a Nutshell: The Language by Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MsgBox Function

Named Arguments

Yes

Syntax

MsgBox(prompt[, buttons][, title][, helpfile, context])

prompt

Use: Required

Data Type: String

The text of the message to display in the message box dialog.

buttons

Use: Optional

Data Type: Numeric

The sum of the Button, Icon, Default Button, and Modality constant values.

title

Use: Optional

Data Type: String

The title displayed in the titlebar of the message box dialog.

helpfile

Use: Optional

Data Type: String

An expression specifying the help file to provide help functionality for the dialog.

context

Use: Optional

Data Type: Numeric

An expression specifying a context ID within helpfile.

Return Value

An Integer value indicating the button clicked by the user.

Description

Displays a dialog box containing a message, buttons, and optional icon to the user. The action taken by the user is returned by the function in the form of an integer value.

Rules at a Glance

  • prompt can contain approximately 1,000 characters, including carriage return characters such as the built-in vbCrLf constant.

  • If the title parameter is omitted, the name of the current application or project is displayed in the titlebar.

  • If the helpfile parameter is provided, the context parameter must also be provided, and vice versa.

  • In VB5 and VB6 applications, when both helpfile and context are passed to the MsgBox function, a Help button is automatically placed on the MsgBox dialog, allowing the user to click and obtain context-sensitive help. However, in VB4, the user was ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required