Microsoft Office Tutorials and References
In Depth Information
The VBA MsgBox Function
End Sub
This example is available on the companion CD-ROM in a file named inputbox
method.xlsm .
Yet another advantage of using Excel’s InputBox method is that Excel performs input
validation automatically. In the GetRange example, if you enter something other than a range address,
Excel displays an informative message and lets the user try again (see Figure 12-4).
Figure 12-4: Excel’s InputBox method performs validation automatically.
The VBA MsgBox Function
VBA’s MsgBox function is an easy way to display a message to the user or to get a simple
response (such as OK or Cancel). I use the MsgBox function in many of the examples in this topic
as a way to display a variable’s value.
The official syntax for MsgBox is as follows:
MsgBox(prompt[,buttons][,title][,helpfile, context])
h prompt : Required. The text displayed in the message box.
h buttons : Optional. A numeric expression that determines which buttons and icon are
displayed in the message box. See Table 12-2.
h title : Optional. The caption in the message box window.
h helpfile , context : Optional. The helpfile and Help topic.
You can easily customize your message boxes because of the flexibility of the buttons
argument. (Table 12-2 lists the many constants that you can use for this argument.) You can specify
which buttons to display, whether an icon appears, and which button is the default.
Search JabSto ::

Custom Search