Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
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.
You don't need any files for this section.
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.
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.
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 |
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:
Sub DisplayAnIcon()
MsgBox "Learning never exhausts the mind"
End Sub
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.
I don't think that da Vinci had ever tried to learn VBA when he said this.
Sub DisplayAnIcon()
MsgBox _
Prompt:="Learning never exhausts the mind", _
Buttons:=vbInformation
End Sub
Sub DisplayAnIcon()
MsgBox _
Prompt:="Learning never exhausts the mind", _
Buttons:=vbInformation
MsgBox _
Prompt:="So why do I feel so tired?", _
Buttons:=vbQuestion
End Sub
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.