VBA MsgBox Icons: Meaning, Constants, and Code Examples

VBA & macros · Updated November 18, 2026

VBA MsgBox icons are selected with a button-style constant: use vbCritical for a serious error, vbQuestion for a prompt, vbExclamation for a warning, or vbInformation for a status message. Add the chosen constant to the MsgBox call alongside its buttons and title; the icon is a standard system graphic, not a custom image.

The four VBA MsgBox icon constants

In desktop VBA, the four icon constants and their numeric values are:

  • vbCritical (16): the critical or stop-style icon, commonly shown as a red error symbol.
  • vbQuestion (32): the question-style icon, traditionally used beside a question asking the user to choose.
  • vbExclamation (48): the warning-style icon, often displayed as an exclamation mark.
  • vbInformation (64): the information-style icon, typically displayed as a lowercase “i” or equivalent symbol.

The constant names are built into VBA, so you can write them directly rather than memorizing or typing their numbers. Their appearance depends on the operating system and Office version. The values identify the icon option; they do not specify its color, shape, or size.

What the icons communicate

An icon is a visual cue, not a substitute for clear wording. Choose it according to the message’s purpose: a failed import is an error, a decision that could discard edits is a warning, and a completed routine is usually information. A question icon can accompany a genuine choice, but the prompt itself should still say exactly what each button will do.

Do not use the most dramatic icon for every message. If routine notifications repeatedly look urgent, users may stop paying attention to them. Likewise, a question icon does not make an unclear “Are you sure?” prompt safe. Explain the consequence, such as “Discard the unsaved changes?” and make the available choices unambiguous.

How to combine an icon with buttons

The basic syntax is MsgBox(prompt, buttons, title). The second argument accepts values for the button set, icon, default button, and other options. Combine the relevant constants with Or. For example, vbYesNo Or vbQuestion requests Yes and No buttons with a question icon. The icon does not determine which buttons appear, and the buttons do not determine the icon.

Here is a complete example that displays an information icon and one OK button:

Sub ShowInformation()
    ' Display a completion message.
    Dim result As VbMsgBoxResult
    result = MsgBox("The import is complete.", _
                    vbOKOnly Or vbInformation, _
                    "Import status")
End Sub

The return value is stored in result, although this example does not need to act on it. Before running a macro, save a copy of the workbook: VBA changes cannot be reversed with Ctrl+Z.

Choosing a suitable icon and button set

Match the icon to the significance of the message and the buttons to the action the user can take. These common combinations are a useful starting point:

  • Completed task: vbOKOnly Or vbInformation.
  • Recoverable problem requiring acknowledgement: vbOKOnly Or vbExclamation.
  • Serious failure: vbOKOnly Or vbCritical, with a useful explanation of what failed.
  • Proceed-or-cancel decision: vbOKCancel Or vbQuestion or, when the choices are genuinely yes and no, vbYesNo Or vbQuestion.

Consider whether a modal pop-up is appropriate at all. A message box interrupts the user and must be dismissed before normal work can continue. For frequent progress updates, a worksheet status cell, the Excel status bar, or a form designed for the task may be less disruptive.

Handling the user’s response

When the user can make a choice, capture the result and branch on the corresponding return constant. For example, with buttons in A2:A20 and a pending task represented by the macro’s operation, this standalone example asks before proceeding; the cell layout is not otherwise relevant to the prompt:

Sub ConfirmRefresh()
    ' Ask before starting a refresh operation.
    Dim answer As VbMsgBoxResult
    answer = MsgBox("Start the refresh now?", _
                    vbYesNo Or vbQuestion Or vbDefaultButton2, _
                    "Confirm refresh")

    If answer = vbYes Then
        MsgBox "Refresh selected.", vbInformation, "Status"
    ElseIf answer = vbNo Then
        MsgBox "Refresh canceled.", vbInformation, "Status"
    End If
End Sub

The example sets the No button as the default using vbDefaultButton2. That is a helpful safeguard when the action should not happen merely because someone presses Enter. The return constants include vbOK, vbCancel, vbYes, and vbNo; compare against the named constant that matches the button rather than assuming a particular number.

Default buttons and other style options

Button constants specify the choices shown: examples include vbOKOnly, vbOKCancel, vbYesNo, and vbRetryCancel. Default-button constants select which button is initially focused: vbDefaultButton1 through vbDefaultButton4. The second, third, and fourth choices have values 256, 512, and 768 respectively; the first is zero. Select a default deliberately, especially when one choice has a destructive effect.

Other options include vbApplicationModal, the usual application-modal behavior, and vbSystemModal, which requests a more intrusive system-modal dialog. There are also options for right alignment, right-to-left reading, and a Help button. These are separate from the icon constants. Combine only options that suit the interface and the user’s locale; a Help button also requires the appropriate help-file and context arguments if it is to provide useful help.

Appearance, customization, and platform limits

The built-in MsgBox function does not let you provide a custom icon file, choose a color, or control the dimensions and layout of the dialog. Its standard icons and window styling are supplied by the host environment. As a result, a screenshot from Windows may not look exactly like the same message displayed by Excel for Mac.

Excel for Microsoft 365 on Windows supports VBA macros when they are permitted by the workbook and security settings. Excel for Mac also supports VBA, though operating-system presentation and some macro capabilities can differ. Excel for the web cannot run VBA macros, so a MsgBox call will not execute there. If a custom graphic, branded layout, or several fields are required, use a VBA UserForm in desktop Excel or another suitable interface rather than trying to alter the built-in dialog.

Common mistakes and troubleshooting

  • Using a number without a reason: 16 happens to mean vbCritical, but named constants make the code easier to understand and maintain.
  • Replacing rather than combining options: pass the icon and button constants together, such as vbOKCancel Or vbExclamation, instead of expecting one option to imply the other.
  • Ignoring the return value: a Yes/No dialog is useful only if the code checks which answer was chosen. Store the result and compare it with vbYes or vbNo.
  • Assuming the icon controls behavior: vbCritical changes the displayed style; it does not stop a macro, roll back edits, or make an operation safer.
  • Expecting the same graphic everywhere: the semantic choice is portable, but exact rendering can vary by platform and Office version.

If a message box does not appear, check that the procedure is actually being called, that macros are enabled under the organization’s security policy, and that execution has not stopped at a breakpoint or error. If the code is intended for a workbook opened in a browser, use an alternative because the web app does not execute VBA.

Frequently Asked Questions

What is the VBA constant for a warning icon?
Use vbExclamation. It is the warning-style icon option; pair it with a button constant such as vbOKOnly if you want to specify the buttons explicitly.

What is the difference between vbCritical and vbExclamation?
Both display a cautionary visual style, but vbCritical is conventionally reserved for a serious error or failure, while vbExclamation suits a warning or condition needing attention. Neither constant changes the program’s logic.

How do I show a question icon with Yes and No buttons?
Combine the options in the buttons argument: vbYesNo Or vbQuestion. Capture the function’s return value and test it against vbYes or vbNo to respond to the choice.

Can I use a custom icon in a VBA MsgBox?
No. The built-in function offers standard icon choices but no argument for a custom image. Create a UserForm if the interface needs a custom graphic or more control over layout.

Do VBA MsgBox icons work in Excel for the web?
No. Excel for the web does not run VBA macros, so a VBA message box will not appear there. Use desktop Excel to run the macro, or redesign the interaction for a web-compatible workflow.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.