The Message Box In VBA

=> One of the best functions in Visual Basic is the Message box. The message box displays a message, optional icon, and selected set of command buttons. The user responds by clicking a button.

=> The statement form of the message box returns no value (it simply displays the box ) :-

MsgBox Message, Type, Title

where

Message     Text message to be displayed
Type            Type of message box (discussed in a bit)
Title             Text in title bar of message box
You have no control over where the message box appears on the screen.

=>  The function form of the message box returns an integer value (corresponding to the button clicked by            the user). Example of use (Response is returned value) :-

Dim Response as Integer
Response = MsgBox(Message, Type, Title)

=>  The Type argument is formed by summing four values corresponding to the buttons to display, any icon to show, which button is the default response, and the morality of the message box.

=>  The first component of the Type value specifies the buttons to display :-
Value     Meaning                                                  Symbolic Constant

0        OK button only                                            vbOKOnly
1       OK/Cancel buttons                                        vbOKCancel
2       Abort/Retry/Ignore buttons                             vbAbortRetryIgnore
3       Yes/No/Cancel buttons                                  vbYesNoCancel
4       Yes/No buttons                                              vbYesNo
5       Retry/Cancel buttons                                      vbRetryCancel

Comments

Popular posts from this blog

50 Excel VBA Oral Interview Questions