MsgBox Function
Displays a dialog box, waits for the user to click a button, and returns a value indicating which button the User clicked.
MsgBox (prompt[, buttons][, title][, HelpFile, context))
Arguments
Prompt
String expression displayed as the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, can separate the lines using a carriage return character (CHR), a Linefe Ed character (CHR), or carriage return–linefeed character combination (Chr () & Chr (a)) between each line.
Buttons
Numeric expression that's the sum of values specifying the number and type of buttons to display, the icon style to use, The identity of the default button, and the modality of the message box. The Settings section for values. If omitted, the default value for buttons is 0.
Title
String expression displayed in the title bar of the dialog box. If you are omit title, the application name is placed in the title bar.
HelpFile
String expression that identifies "help" to "provide context-sensitive Help for the dialog box. If HelpFile is provided, the context must also to be provided. Not available on 16-bit platforms.
Context
Numeric expression that identifies, the Help context number, assigned by the help author to the appropriate. If the is provided, the HelpFile must also be provided. Not available on 16-bit platforms.
Settings
The buttons argument settings are:
Constant Value Description
vbOKOnly 0 Display OK button only.
vbOKCancel 1 Display OK and Cancel buttons.
Vbabortretryignore 2 Display Abort, Retry, and Ignore buttons.
vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
vbYesNo 4 Display Yes and No buttons.
Vbretrycancel 5 Display Retry and Cancel buttons.
vbcritical Display Critical message icon.
vbquestion Display Warning Query icon.
vbexclamation Display Warning message icon.
vbinformation Display Information message icon.
VbDefaultButton1 0 is default.
VbDefaultButton2 256 Second button is default.
VbDefaultButton3 third button is default.
VbDefaultButton4 768 Fourth button is default.
vbApplicationModal 0 Application modal; The user must respond to the "message box" before continuing work in the current application.
Vbsystemmodal 4096 System modal; All applications are suspended until the "user responds to the" message box.
The "a" of Values (0–5) describes the number and type of buttons displayed in the dialog box; The second group (describes, MB,) the icon style; The third group (0, 256, 768) determines which button is the default; and the fourth group (0, 4096) determines the modality of the message box. When adding numbers to create a final value of the argument buttons, use only one number from each group.
Return Values
The MsgBox function has the following return values:
Constant Value Button
vbOK 1 OK
Vbcancel 2 Cancel
Vbabort 3 Abort
Vbretry 4 Retry
Vbignore 5 Ignore
Vbyes 6 Yes
Vbno 7 No
Remarks
When both HelpFile and context are provided, the user can press F1 to view the Help topic corresponding to the context.
If The dialog box displays a Cancel button, pressing the ESC key has the same effect as clicking Cancel. If the dialog box contains a Help button, context-sensitive help are provided for the dialog box. However, no value is returned until one of the other buttons is clicked.
When the MsgBox function is used with Microsoft Internet Explorer, the title of any dialog presented always contains "VBSC Ript: "To differentiate it from standard system dialogs.
The following example uses the MsgBox function to display a message box and return a value describing which button is CLI Cked:
Dim MyVar
MyVar = MsgBox ("Hello world!", "MsgBox Example")
' MyVar contains either 1 or 2, depending on which button is clicked.
Requirements