Page 134 - Excel Progamming Weekend Crash Course
P. 134
h540629 ch09.qxd 9/2/03 9:33 AM Page 109
Session 9 — Working with Text 109
Providing online help for your Excel applications is covered in Session 30.
Cross-Ref
The value passed to the buttons argument determines three things: which buttons are
displayed, which icon is displayed, and which button (if more than one is displayed) is the
default and will be selected when the user presses Enter. To specify two or three items in
this argument, combine the corresponding constants from Table 9-1 using the Or operator.
For example, to display the Yes, No, and Cancel buttons, a question mark icon, and have the
second button (No in this case) be default, you would use the following syntax:
vbYesNoCancel Or vbQuestion Or vbdefaultButton2
Here’s a real example that displays the message “Exit without saving” along with Yes, No,
and Cancel buttons, a question mark icon, with the No button as the default:
reply = MsgBox(“Exit without saving?”, vbYesNoCancel Or vbQuestion Or _
vbdefaultButton2)
Instead of the Or operator you can simply add button constants together
when needed.
Note
The MsgBox function returns an integer value that identifies the button the user selected
to close the dialog box. These return values are represented by the following constants,
whose meanings should be clear; the value of each constant is given in parentheses:
vbOK (1)
vbCancel (2)
vbAbort (3)
vbRetry (4)
vbIgnore (5)
vbYes (6)
vbNo (7)
Here’s an example of using the return value:
Dim reply As Integer
reply = MsgBox(“Exit without saving?”, vbYesNoCancel Or vbQuestion Or _
vbdefaultButton2)
If reply = vbYes Then
‘ Code to exit without saving here.
Elseif reply = vbNo Then
‘ Code to save then exit here.
Else
‘ Code to return to program here.
End If