Microsoft Office Tutorials and References
In Depth Information
The VBA MsgBox Function
Case vbNo
‘ ...[code if Ans is No]...
End Select
End Sub
Table 12-3: Constants Used for Msgbox Return Value
Constant
Value
Button Clicked
vbOK
1
OK
vbCancel
2
Cancel
vbAbort
3
Abort
vbRetry
4
Retry
vbIgnore
5
Ignore
vbYes
6
Yes
vbNo
7
No
The variable returned by the MsgBox function is an Integer data type. Actually, you don’t even
need to use a variable to utilize the result of a message box. The following procedure is another
way of coding the GetAnswer procedure:
Sub GetAnswer2()
If MsgBox(“Continue?”, vbYesNo) = vbYes Then
‘ ...[code if Ans is Yes]...
Else
‘ ...[code if Ans is No]...
End If
End Sub
The following function example uses a combination of constants to display a message box with a
Yes button, a No button, and a question mark icon; the second button is designated as the default
button (see Figure 12-5). For simplicity, I assigned these constants to the Config variable.
Figure 12-5: The buttons argument of the MsgBox function determines which buttons appear.
 
Search JabSto ::




Custom Search