BLOGS BY TOPIC
BLOGS BY AUTHOR
BLOGS BY YEAR
The MsgBox command in Visual Basic for Applications allows you to display basic messages, but you can also make it prettier, and even use it to ask questions or display multiple-line messages! Read on to find out more about this versatile VBA command.
- Using MsgBox to Display Messages in VBA Macros
- Displaying Message Boxes
- Joining Bits of a Message Together
- Customising your Message Box (this blog)
- Using MsgBox to Ask Questions
Posted by Andy Brown on 28 September 2011
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Customising your Message Box
You can add a few bells and whistles to a message box - but only a few.
You can display 4 different symbols:
So, for example, this would display a message box with an exclamation mark symbol and an OK button (bizarrely, you add your choices together):
'display a message with an exclamation mark symbol
MsgBox "Cats like plain crisps", vbExclamation + vbOKOnly
In addition to the symbols above, you can control which buttons you see as follows:
|Key word||Buttons that you get|
|vbOkCancel||OK and Cancel|
|vbYesNo||Yes and No|
|vbAbortRetryIgnore||Abort Retry and Ignore|
|vbRetryCancel||Retry and Cancel|
|vbYesNoCancel||Yes No and Cancel|
To understand why you would display different combinations of buttons, see the last entry in this blog about asking questions with message boxes.