


Notice the first dialog box has an X in its upper-right corner, which is disabled in the second. The first ans will have the value 1 or 2 and the second ans will be 6 or 7, depending on which buttons were clicked. VB ConstantĪns = MsgBox ( "Click a button.", vbOKCancel ) ans = MsgBox ( "Click a button.", ( vbYesNo + vbQuestion )) The function’s return value indicates which button was clicked. The following table identifies the possible arrangement of buttons. For this tutorial we will focus on the 7 standard buttons labeled OK, Cancel, Abort, Retry, Ignore, Yes, and No which can appear together in the dialog box using 1, 2, or 3 buttons.
#Excel vba create popup window plus#
One value from each of the four groups (buttons, icons, defaults, modality) plus up to four other values can be combined by addition. (As stated earlier, the function supports a Help button that can only be used to open an optional Windows Help file the Help button will be ignored here.)Īll of the possible settings for the buttons argument are listed in the MsgBox reference. If the title argument is supplied, it will be displayed in the dialog’s title bar otherwise, the default title will be, for example, Microsoft Excel.įor this tutorial we are primarily concerned with the number and arrangement of buttons and the function’s return value (a whole number from 1 to 7) identifying which button was clicked. The optional buttons argument enables specifying the number and arrangement of buttons, an optional icon image (with related sound), the default button, modality of the dialog box, and some other features. Only the prompt argument, which is a string, is required it represents the message to be displayed in the dialog box. Therefore, we will develop a VBA module with procedures that permit the standard button labels to be changed. For example, we might want buttons labeled Start, Stop, Open, Close, Jack, Jill, etc. Sometimes the standard button labels might be inadequate. (We will ignore the possible addition of another button labeled Help because it can only be used to open a Windows Help file.) The function waits until the user clicks a button then returns an Integer indicating the user’s choice. VBA’s MsgBox function displays a message in a dialog box with 1, 2, or 3 standard buttons labeled OK, Cancel, Abort, Retry, Ignore, Yes, or No. Even though we’ve shown some neat MsgBox tricks, most of our previous tutorials have not discussed the use of MsgBox buttons to provide choices for directing a procedure.
#Excel vba create popup window how to#
We even taught you how to change the text color of a MsgBox. For example, our Create Your First Macro tutorial illustrates the ubiquitous MsgBox("Hello World") macro. Often the VBA MsgBox function is used to communicate information. We have published many tutorials showing how to create your own VBA macros and procedures.
