VBA MsgBox: How to Display Messages in Excel

VBA & macros · Updated November 18, 2026

In Excel VBA, MsgBox displays a dialog box containing a message and optional buttons, and it can return the button the user clicked. For example, MsgBox "Task complete.", vbOKOnly + vbInformation, "Status" shows an information icon, an OK button, and a title.

What VBA MsgBox Does

MsgBox is a built-in VBA function, available in Excel and other Office desktop applications. A macro can use it to report that work finished, explain why it is stopping, or ask a person to confirm a choice. The box appears while the macro is running, and the user generally needs to dismiss it or choose a button before that code continues. This pause makes it useful for short, important interactions, but unsuitable for frequent updates during a long automated process.

A message box is not the same as a worksheet cell, a status-bar message, or a custom dialog. It is a compact, temporary window with a set of standard buttons, optional icon, and optional title. VBA determines what happens next: the box itself does not automatically save a workbook, cancel a macro, or reverse changes. If the macro should respond differently to Yes and No, the code must examine the function’s return value.

Basic Syntax and Arguments

The general form is MsgBox(prompt, buttons, title, helpfile, context). In ordinary use, the first three arguments are the ones that matter. The prompt is the text to display; buttons selects the button arrangement, icon, and default button; and title supplies the text in the dialog’s title bar. The later helpfile and context arguments are for linking to a help file and a specific help topic, and most Excel macros do not need them.

The arguments after prompt are optional, so a basic call can be as short as MsgBox "Saved". If you leave out the title, VBA uses the application name. If you leave out buttons, the dialog has an OK button and no special icon. For clarity, it is often better to state the intended buttons and title explicitly, especially when the box asks the user to make a decision.

VBA constants make button settings easier to read than numeric values. Combine compatible constants with + or Or. For example, vbYesNo + vbQuestion requests Yes and No buttons with a question icon. The buttons and icon are presentation choices; they do not decide the macro’s logic. The code has to check the result separately.

Make and Run a Simple Excel Macro

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11. In the editor, choose Insert > Module, enter a procedure in the module, then run it with F5 while the cursor is inside the procedure. You can also return to Excel and use Developer > Macros, select the macro, and choose Run. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon.

Save a copy of the workbook before running a macro: VBA changes cannot be undone with Ctrl+Z. This example displays a simple status message. The variable is declared explicitly and holds the prompt text.

Sub ShowStatusMessage()
    Dim message As String

    ' Set the text shown to the user.
    message = "The report is ready."
    MsgBox message, vbOKOnly + vbInformation, "Report status"
End Sub

For a workbook containing VBA, save in a macro-enabled format such as Excel Macro-Enabled Workbook (.xlsm); saving as a standard .xlsx file does not preserve VBA code. On Mac, Excel also supports VBA and message boxes, although some VBA features and operating-system integrations differ from Windows. The Visual Basic Editor can be opened from the Developer tab or with Option+F11 on many Mac keyboards; the Fn key may also be required, depending on keyboard settings. Excel for the web can open a workbook containing macros, but it cannot create, edit, or run VBA macros.

Choose Buttons and Read the User’s Answer

When you assign the result of MsgBox to a variable, its type should normally be VbMsgBoxResult. Common return values include vbOK, vbCancel, vbYes, and vbNo. A confirmation dialog is useful before an action that could overwrite data or affect many cells. The following example runs the confirmation branch only when the user chooses Yes.

Save a copy of the workbook before running this macro because its changes cannot be undone with Ctrl+Z. This example only reports the choice; it does not perform a destructive action.

Sub AskBeforeContinuing()
    Dim answer As VbMsgBoxResult

    ' Ask for a clear Yes or No response.
    answer = MsgBox("Continue with the next step?", _
                    vbYesNo + vbQuestion + vbDefaultButton2, _
                    "Confirm action")

    If answer = vbYes Then
        MsgBox "You chose Yes.", vbOKOnly, "Choice"
    Else
        MsgBox "You chose No.", vbOKOnly, "Choice"
    End If
End Sub

Here, vbDefaultButton2 makes No the initially selected button, which can reduce accidental confirmation. Other useful button arrangements include vbOKCancel, vbRetryCancel, and vbAbortRetryIgnore. Choose button labels that describe real choices. Do not offer Yes and No if the user needs to choose between actions with different meanings, and do not assume that closing a dialog is equivalent to choosing a particular button without checking the result.

Icons, Titles, and Multiline Messages

Icons can communicate the kind of message, but they do not change what the macro does. Common choices are vbInformation for a routine notice, vbExclamation for a caution, vbQuestion for a question, and vbCritical for a serious error. Use them sparingly: an icon should reinforce the wording, not substitute for a clear explanation. A meaningful title, such as “Import results” or “Confirm deletion,” is more helpful than a generic title like “Message.”

To break a long prompt into readable lines, join strings with vbCrLf, the VBA constant for a carriage return and line feed. For example, a macro could build a prompt from a summary and a question. Keep the text concise: a message box is a small dialog, not a good place for a long report or a dense set of instructions. If users need to review several records, put the details in a worksheet or a custom form instead.

Standard MsgBox buttons have fixed captions. VBA cannot use this function to rename OK to “Continue,” or Yes to “Replace file.” If the exact wording of buttons matters, use a UserForm with command buttons and code their behavior. A UserForm takes more work, but it gives control over button labels, layout, and additional fields.

Practical Uses and Good Design

Good uses include a brief completion notice, a warning that required input is missing, or a confirmation before a consequential step. The message should tell users what happened or what will happen, then state what they need to do. “There are blank cells in column B. Continue anyway?” is more actionable than “Warning.” For a completion message, mention the outcome, such as the number of rows processed, rather than merely saying “Done.”

Avoid placing a message box inside a loop that runs once per row. If a macro processes 500 records and displays one box for each, it forces 500 interruptions and makes automation impractical. Instead, collect a count or list of issues while the procedure runs and show one summary at the end. Similarly, a message box is not a reliable progress indicator for work that takes time; a status-bar update or a modeless UserForm may be more appropriate.

Do not use a message box as the only record of an important result. Its text disappears when dismissed, and it is not automatically written to the workbook. If the user needs to audit the outcome later, put a timestamped summary on a worksheet or save it to a suitable log. Keep any personal or confidential information out of a dialog that might be visible to someone looking at the screen.

Common Problems and Troubleshooting

If no dialog appears, check that the macro actually ran and reached the MsgBox line. A conditional branch may have skipped it, or an earlier error may have stopped execution. In the Visual Basic Editor, use F8 to step through code line by line on Windows; on Mac, the matching shortcut can depend on the keyboard and function-key settings. You can also set a breakpoint by clicking beside a line and inspect the code path.

If the dialog appears but the macro does the wrong thing afterward, inspect how the return value is compared. The result should be compared with a named constant such as vbYes, not with the text “Yes.” The function returns a numeric result represented by a VBA constant. Also confirm that the selected button set can actually return the value your code expects; an OK-only dialog cannot return vbYes.

For a syntax error, check commas, parentheses, quotation marks, and line continuations. A long call split across lines needs a space and underscore at the end of each continued line. The prompt must be a string expression, and text inside VBA string literals uses straight double quotation marks. If the title or message is assembled from worksheet values, check that the values are converted or joined as intended and that the resulting prompt remains readable.

A dialog that seems to freeze Excel is often waiting for a click: a normal message box is modal, so the macro pauses until the user responds. If the box is hidden behind another window, use the task switcher or bring Excel to the foreground. Avoid system-modal settings for routine messages; they can interrupt work outside Excel and are rarely appropriate for workbook macros.

Macro Safety and Platform Limits

A message box is only a user interface feature; it does not make a macro safe. VBA code can edit or delete workbook data, and a macro can run other actions before or after showing a prompt. Only enable macros in files from sources you trust, and review unfamiliar code before running it. Excel’s macro security settings are designed to reduce risk, so do not disable protections simply because a workbook displays a warning that macros are blocked.

Before testing a macro that changes cells, work on a copy. Ctrl+Z does not undo VBA actions in the usual way, even if the macro itself displayed a confirmation dialog. Add explicit checks and make a backup or provide a deliberate recovery approach if the procedure changes important data. A Yes/No prompt is not a substitute for validating the selected range, checking file paths, or handling errors.

Excel for the web does not run VBA, so a workbook’s macro-enabled file may need to be opened in the desktop Excel application to use its macros. Excel for Mac supports many standard VBA operations, including ordinary MsgBox calls, but platform-specific APIs, file access, and other integrations may need changes. If a workbook is shared across Windows and Mac, keep the message-box code simple and test the complete macro on the platforms where it will be used.

Alternatives to MsgBox

Choose the interface based on how much interaction is needed. A worksheet cell is better for a persistent status or a result the user may revisit. Excel’s status bar can show a short progress or status message without pausing the macro. A UserForm is preferable when the user needs custom button text, several inputs, or a dialog that remains open while other work continues. A message box is usually best when one short interruption is genuinely necessary.

For automated work, consider whether any dialog is needed at all. A macro launched by another process or scheduled workflow may be unable to receive a click, leaving it waiting indefinitely. In that situation, write the outcome to a log or worksheet and handle errors in code rather than asking a person to respond. Use MsgBox for interactive desktop tasks, not as a replacement for structured logging or error handling.

Frequently Asked Questions

How do I show a message box in Excel VBA?
Put a call such as MsgBox "Finished", vbOKOnly + vbInformation, "Status" in a VBA procedure, then run the macro in desktop Excel. The first argument is the prompt, followed here by button/icon settings and a title.

How do I make a VBA MsgBox with Yes and No?
Use vbYesNo in the buttons argument, then store the result in a VbMsgBoxResult variable and compare it with vbYes or vbNo. The buttons alone do not cause different actions; your code must handle each answer.

Can I change the text on MsgBox buttons?
No. The built-in function uses standard button captions such as OK, Cancel, Yes, and No. Use a VBA UserForm if you need custom captions or a more flexible layout.

Why does my macro stop at MsgBox?
A standard message box pauses the procedure until someone responds. If Excel appears stuck, check whether the dialog is behind another window. For unattended automation, remove the prompt and record the result another way.

Does VBA MsgBox work in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in desktop Excel for Windows or Mac to run a VBA procedure that uses MsgBox.

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.