MODULES▼
LESSONS▼
TOPICS▼
You can make a message box look more interesting by adding an icon to it. This page describes how to display icons on a message box.

Icons are a good way to make a message look more intimidating.
Files Needed
You don't need any files for this section.
Completed Code
You can click here to download a workbook which contains the completed code.
To begin this part of the lesson, create a new workbook and in the VBE insert a new module.
Displaying Icons on a Message Box
To change the icon displayed on the message, confusingly you use the Buttons parameter. You can see a list of options for this parameter by typing a comma after the prompt of a message box. Create a new subroutine called ChangingTheIcon and add the code shown in the diagram below:

You can choose which icon to use from the list of constants which appears.
If the list of constants disappears, you can press CTRL + SHIFT + J to redisplay it.
Choose the vbExclamation constant from the list:

Well, you can't say you weren't warned.
Running this code produces the message box shown below:

I'm not quite clear on what we're being warned about.
The Available Icons
You can display one of four icons on a message box, as shown in the table below:
Constant | Icon | Sample code |
---|---|---|
vbCritical |
![]() |
MsgBox "Something went wrong!", vbCritical |
vbExclamation |
![]() |
MsgBox "This might be a bad idea!", vbExclamation |
vbInformation |
![]() |
MsgBox "Just FYI", vbInformation |
vbQuestion |
![]() |
MsgBox "Are you sure?", vbQuestion |
Using Named Parameters
You might find your code more readable if you use named parameters and continuation characters. Create a new subroutine called NamingArguments and add code to it as shown below:

Using multiple lines and named arguments means more typing for you, but it makes your code more readable.
To practise adding an icon to a message box:
- Using any workbook, open the VBE and insert a new module.
- Create a subroutine called CustomisingMessages and add the code shown below (feel free to alter the prompt):
Sub DisplayAnIcon()
MsgBox "Learning never exhausts the mind"
End Sub
- Alter your code to display an icon on the message box:
Sub DisplayAnIcon()
MsgBox "Learning never exhausts the mind", vbInformation
End Sub
Remember that there are four different icons: vbCritical, vbExclamation, vbInformation and vbQuestion. Use the one that you feel is most appropriate for your message.
- Test your code by clicking within the subroutine and pressing F5 to run it.

I don't think that da Vinci had ever tried to learn VBA when he said this.
- Alter the code to use named arguments and continuation characters.
Sub DisplayAnIcon()
MsgBox _
Prompt:="Learning never exhausts the mind", _
Buttons:=vbInformation
End Sub
- Add a second message box with a different message and icon.
Sub DisplayAnIcon()
MsgBox _
Prompt:="Learning never exhausts the mind", _
Buttons:=vbInformation
MsgBox _
Prompt:="So why do I feel so tired?", _
Buttons:=vbQuestion
End Sub
- Run the subroutine to check that you see each message then save and close the workbook.