The message box function is mainly used to prompt the user for a click of a button, or to deliver a message. Please keep in mind you don't use parenthesis [ ( and ) ] unless you are assigning the message box to a variable or you are using it in a statement.


MsgBox "Main text here", , "Title here"

This syntax will create the following alert: MsgBox

There are 3 main sections to a message box. The first being the main text, the second being the type of box, and the third being the title. In the main text area, you write the message you want the box to display. You put the message in quotes. After the ending quote, you can put a comma [,] after it, and then put the type. The following are the different types of message boxes (Each type can be replaced with the number and it will do the same thing, the number is shown before the type in the example below):

0 = vbOKOnly - OK button only
1 = vbOKCancel - OK and Cancel buttons
2 = vbAbortRetryIgnore - Abort, Retry, and Ignore buttons
3 = vbYesNoCancel - Yes, No, and Cancel buttons
4 = vbYesNo - Yes and No buttons
5 = vbRetryCancel - Retry and Cancel buttons
16 = vbCritical - Critical Message icon
32 = vbQuestion - Warning Query icon
48 = vbExclamation - Warning Message icon
64 = vbInformation - Information Message icon
0 = vbDefaultButton1 - First button is default
256 = vbDefaultButton2 - Second button is default
512 = vbDefaultButton3 - Third button is default
768 = vbDefaultButton4 - Fourth button is default
0 = vbApplicationModal - Application modal (the current application will not work until the user responds to the message box)
4096 = vbSystemModal - System modal (all applications wont work until the user responds to the message box)

In order to get the value returned by the user, you need either a Comparison or a Variable (With a variable, you will need a comparison later to see the value anyway). To check the variable, you would use the type, such as vbYesNo, and put a [vb] before the input you're checking it for. The following is an example using an If Statement with the vbYesNo [4] parameter.

If MsgBox("Do you have five fingers?", vbYesNo, "Question") = vbYes Then MsgBox "Most people do."

If you don't put in a type at all, such as in the first example at the top of the page, it would default to vbOkayOnly. Here is the same code using the number [4] instead of the word name [vbYesNo].

If MsgBox("Do you have five fingers?", 4, "Question") = vbYes Then MsgBox "Most people do."

In both cases, it would create a box like this: VbYesNo

In order to use the different default button parameters mentioned above, you would add a [+] after the type, and then which button to default on. If you don't include the button to defualt on, it automatically defaults on the first button. The following example is the same vbYesNo box as above, only with the second button defaulted:

If MsgBox("Do you have five fingers?", vbYesNo + vbDefaultButton2, "Question") = vbYes Then MsgBox "Most people do."

This would make a box like this: DefaultButton2

You can use the same principle of the plus [+] character to add the vbCritical/Question/Exclamation too. Here's an example of a vbYesNo that is with a vbInformation:

If MsgBox("Do you have five fingers?", vbYesNo + vbInformation, "Question") = vbYes Then MsgBox "Most people do."

This creates the following: InfoPlus

Perhaps you wanted that same thing only with the second button defaulted? Here's the code:

If MsgBox("Do you have five fingers?", vbYesNo + vbInformation + vbDefaultButton2, "Question") = vbYes Then MsgBox "Most people do."

Naturally, it would look like this: InfoPlusPlus

Some of the other types mentioned were vbCritical [16], vbQuestion [32], and vbExclamation [48]. Here is an example of the vbCritical:

MsgBox "", vbCritical

That would look like VbCritical

With the 3 different types, the red x would be replaced with a different symbol. vbCritical [16], vbQuestion [32], and vbExclamation [48] in order look like: Symbols

If you wanted to display a variable in a message box, you would simply use the following code. In this example, the variable name is "TXT", and it contains the text "These are words."

TXT = "These are words."
MsgBox TXT

This makes the following box: VariableMsgBox

If you don't want to include all the parameters (The main text, type, and title), then you simply leave that space empty. Such as if I only wanted the main text, I would do the following:

MsgBox "Main text here"
Only type:
MsgBox "", TypeHere
Only title:
MsgBox "", , "Title here"
Only main text and title:
MsgBox "Main text here", , "Title here"
Only main text and type:
MsgBox "Main text here", TypeHere
Only type and title:
MsgBox "", TypeHere, "Title here"


InputBox (Function)


Remember, if you ever need help, you can ask BusyCityGuy on his talk page.

Did you find what you needed?

The poll was created at 23:16 on June 10, 2012, and so far 69 people voted.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.