WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 482 reviews for our classroom and online training
Using MsgBox to Display Messages in VBA Macros
Part four of a five-part series of blogs

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.

  1. Using MsgBox to Display Messages in VBA Macros
  2. Displaying Message Boxes
  3. Joining Bits of a Message Together
  4. Customising your Message Box (this blog)
  5. Using MsgBox to Ask Questions

This blog is part of our Excel macros online tutorial series.  Our main business is running training courses in Excel, courses in VBA and training in many other Microsoft applications.

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.

Different Symbols

You can display 4 different symbols:

Key word Symbol
vbCritical MsgBox symbol - stop
vbQuestion MsgBox symbol - question mark
vbExclamation MsgBox symbol - exclamation mark
vbInformation MsgBox symbol - information

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

Different Buttons

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
vbOkOnly OK only
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.

This blog has 0 threads Add post