Excel VBA Popup Message: Show a MsgBox in a Macro

VBA & macros · Updated November 3, 2026

Excel VBA Popup Message: Show a MsgBox in a Macro

To show a popup message in Excel VBA, use the MsgBox function in a macro, such as MsgBox "Finished", vbInformation, "Update complete". It displays a dialog with text, optional buttons and an optional title; you can also check which button the user clicked and respond in your code.

What an Excel VBA popup message does

A VBA popup is a dialog box shown while a macro runs. It can notify someone that a task finished, warn them about a potentially important action, or ask a simple question before the macro continues. The standard VBA tool for this is MsgBox, short for message box.

A message box is different from text written into a worksheet cell. It appears on top of Excel and generally requires the user to dismiss it or choose a response before the macro proceeds. That makes it useful for brief, timely messages, but disruptive if used repeatedly in a long or unattended process.

For a simple notification, the general syntax is MsgBox prompt, buttons, title. The prompt is the message text. The buttons argument controls the available buttons and optional icon or default button; the title is the text in the dialog’s title bar. The buttons and title arguments are optional, but specifying them makes the message clearer.

How to add a MsgBox to a macro

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11. On a Mac, use the Developer tab’s Visual Basic command; the keyboard shortcut can depend on the keyboard and function-key settings. In the editor, choose Insert > Module, then put a macro in the new module. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon on Windows, or Excel’s ribbon settings on Mac.

This complete example displays an informational message:

Sub ShowCompletionMessage()
    Dim message As String

    ' Set the text that the dialog will display.
    message = "The report is ready."
    MsgBox message, vbInformation, "Report status"
End Sub

To run it, click inside the procedure in the Visual Basic Editor and press F5, or return to Excel, choose Developer > Macros, select ShowCompletionMessage, and click Run. On Mac, the Developer tab also provides access to macros; available shortcuts can vary by keyboard. Before running any macro that changes a workbook, save a separate copy. Macro actions cannot be reversed with Ctrl+Z.

When you want the macro to run the message at a particular point, place the MsgBox line at that point in the procedure. For instance, put it after a report has been created if it should confirm completion. It does not need to be the last line, although code after it will wait until the user dismisses the dialog.

Choose buttons, icons, and a clear title

The second argument can combine VBA’s built-in constants to set buttons, an icon, and which button is selected by default. Use the named constants rather than unexplained numbers so another person can understand the intent. Common choices include:

  • vbOKOnly or vbOKCancel for confirmation or a chance to cancel.
  • vbYesNo or vbYesNoCancel for a question that needs a decision.
  • vbInformation, vbExclamation, vbQuestion, or vbCritical for a matching icon.
  • vbDefaultButton1, vbDefaultButton2, or vbDefaultButton3 to choose the initially selected button when that button exists.

Combine options with the VBA Or operator. For example, a question with Yes and No buttons, a question icon, and No selected by default can be written as vbYesNo Or vbQuestion Or vbDefaultButton2. The icon should communicate the message’s purpose, not exaggerate it: a routine completion notice usually does not need a critical-error symbol.

Keep the title specific, such as “Import status” or “Confirm deletion,” rather than leaving a generic title that gives little context. Make the prompt understandable on its own. A person may see the dialog without remembering which sheet or button they just used.

Use the response to control what happens next

MsgBox can return a value identifying the button clicked. Store that result in a variable of type VbMsgBoxResult and compare it with a named constant. This lets a macro take different actions based on the user’s answer rather than merely displaying a question.

Sub ConfirmArchive()
    Dim answer As VbMsgBoxResult

    ' Ask before moving the current report.
    answer = MsgBox("Archive this report now?", _
                    vbYesNo Or vbQuestion Or vbDefaultButton2, _
                    "Confirm archive")

    If answer = vbYes Then
        MsgBox "The archive step can continue.", vbInformation, "Confirmed"
    Else
        MsgBox "No changes were requested.", vbInformation, "Cancelled"
    End If
End Sub

The first dialog returns vbYes or vbNo, so the comparison determines which branch runs. In a real macro, replace the illustrative confirmation messages with the actual archive or cancellation logic. Do not make the default button the risky action when a mistaken Enter key could cause unwanted changes. The default-button setting only chooses the initial selection; it does not replace a meaningful confirmation or a backup.

Format messages and handle longer text

For separate lines in a prompt, join text with vbCrLf, VBA’s carriage-return-and-line-feed constant. For example, a macro can show a short status followed by a count or next step. Keep the wording concise: a message box is best for a small amount of information, not a long report or a collection of many choices.

If the message is assembled from worksheet values, build the text in a variable before calling MsgBox. That makes it easier to check the wording and avoid showing blank or misleading details. Be careful not to include confidential data in a dialog where someone else might see the screen. For lengthy instructions, multiple fields, or a choice list, a worksheet, a UserForm, or a saved report is generally more suitable than a crowded standard dialog.

A message box is modal: the user must respond before continuing to interact with the workbook in the ordinary way. This behavior is helpful when the answer matters to the next step, but can frustrate users if a macro opens a chain of dialogs or pauses during unattended work. Use one clear prompt at a decision point rather than adding a popup after every minor operation.

MsgBox compared with InputBox and worksheet messages

Use MsgBox when you need to display information or collect a limited button response. Use InputBox when the macro needs a simple text entry, such as a short name. An InputBox is not a replacement for a form when you need to validate several fields, present a dropdown, or explain a complicated choice. Excel’s Application.InputBox also offers a Type argument for restricting the kind of input; its return and cancellation handling should be designed deliberately.

Put a message in a worksheet cell when it should remain visible, be printable, or be available after the macro finishes. A status-bar message can be less intrusive for brief progress updates, while a UserForm offers more control over layout and input. Each option serves a different purpose: popups interrupt, cells persist, and forms support richer interaction.

Common problems and how to fix them

  • The macro does not appear to run: Check that the workbook is saved in a macro-enabled format, typically .xlsm, and that macros are permitted under the organization’s security settings. Do not enable macros in an untrusted file just to see what happens.
  • The code is in the wrong place: A normal procedure such as ShowCompletionMessage can go in a standard module. Event procedures, such as code that responds to a worksheet change, belong in the relevant worksheet or workbook code module.
  • The dialog appears at an inconvenient time: Find the line that calls MsgBox and check the order of the procedure. A message box pauses execution until it is dismissed, so a loop can produce many popups if the call is placed inside it.
  • The message shows literal characters or odd spacing: Check the quotation marks and concatenation operators. To create a line break in VBA text, use vbCrLf rather than typing a spreadsheet formula into the macro.
  • The macro works on desktop but not in Excel for the web: Excel for the web cannot run or edit VBA macros. Open the workbook in the desktop Excel application to use VBA. The desktop Mac app supports VBA, although some Excel features and editor details differ from Windows.

On Windows, macro settings are available from File > Options > Trust Center > Trust Center Settings > Macro Settings, but organizational policies may control those choices. A blocked macro is not always a coding problem. Follow your organization’s approved process instead of lowering security protections broadly.

Good practices for reliable popup messages

Write prompts as a direct statement or question and make the consequence of a choice clear. “Continue with deleting the selected rows?” is more useful than “Proceed?” when deletion is the action at stake. If the macro can identify the affected sheet, file, or number of records, include that context so the user can catch mistakes.

  • Use a popup only when the user needs to notice or decide something immediately.
  • Use an appropriate icon and button set, and make sure the code handles every response the dialog offers.
  • Prefer a safer default button for destructive or difficult-to-reverse actions.
  • Test normal, cancelled, and unexpected situations using a copy of the workbook.
  • Save user-facing messages in one place if the workbook has many macros, so wording can be maintained consistently.

For macros that process many records, consider reporting a summary at the end instead of interrupting the process for each record. If progress must be shown while work continues, a status update or custom form may be more appropriate. A well-chosen popup gives useful feedback without turning a routine task into a sequence of interruptions.

Frequently Asked Questions

What is the VBA code for a simple popup?
Use MsgBox "Your message", vbInformation, "Title" inside a VBA procedure. For a complete macro, put the call between Sub and End Sub.

How do I make a popup with Yes and No buttons?
Set the buttons argument to vbYesNo, optionally combined with an icon such as vbQuestion. Store the function’s result and compare it with vbYes or vbNo to decide what the macro should do.

Can a VBA popup appear automatically when a workbook opens?
Yes. A workbook-open event procedure can call a message box when the workbook opens, but it belongs in the ThisWorkbook code module and depends on macros being enabled. Consider whether an automatic interruption is helpful to everyone who opens the file.

Can VBA popups run in Excel for the web?
No. Excel for the web does not run VBA macros. Use desktop Excel for VBA, or consider Office Scripts and other web-compatible approaches if the workbook must be automated in a browser.

Can I undo a macro after dismissing its popup?
Usually, you cannot use Ctrl+Z to undo changes made by a VBA macro. Save a backup copy before running code that edits data, and have the macro make its own recovery copy if the workflow requires one.

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.