Excel VBA MsgBox Custom Buttons and Choices

VBA & macros · Updated November 21, 2026

Excel VBA’s built-in MsgBox cannot create arbitrary button captions such as “Continue” or “Skip”; it offers fixed button sets such as Yes/No and OK/Cancel. If you need custom wording, a different number of buttons, or custom actions, build a VBA UserForm instead.

What MsgBox Buttons Can and Cannot Do

MsgBox is a quick way to ask a question or show a short notice without designing a form. Its buttons are chosen from a set of predefined combinations. You can set the message, title, icon, default button, and some display options, but you cannot change the built-in captions or add a fourth button.

That distinction matters because “custom buttons” can mean two different things. If you mean choosing which standard buttons appear, such as Yes and No, MsgBox already supports that. If you mean changing the labels to “Save,” “Discard,” and “Keep Editing,” or making each button run a distinct workflow, use a UserForm.

The built-in dialog is useful for small, familiar decisions. A UserForm is more suitable when the prompt needs specialized wording, extra fields, several choices, or a consistent layout across multiple screens.

Choose a Built-In Button Set

The second argument of MsgBox specifies the button combination. These are the main button constants:

  • vbOKOnly: one OK button. This is the default if you omit the buttons argument.
  • vbOKCancel: OK and Cancel.
  • vbAbortRetryIgnore: Abort, Retry, and Ignore.
  • vbYesNoCancel: Yes, No, and Cancel.
  • vbYesNo: Yes and No.
  • vbRetryCancel: Retry and Cancel.

Pick the set that matches the user’s actual decision. For example, use Yes/No when both responses are meaningful and there is no separate cancellation state. Use Yes/No/Cancel if the person should be able to leave the question unanswered and return to the workbook. Avoid presenting “Abort,” “Retry,” and “Ignore” unless those terms genuinely describe the choices.

How the Buttons Argument Works

The basic syntax is MsgBox(prompt, buttons, title). The prompt is the message, buttons combines button, icon, and default-button constants, and title supplies the dialog’s caption. The full function also accepts optional help-file and context arguments, but ordinary prompts rarely need them.

Constants can be combined with the + operator. For example, vbYesNo + vbQuestion + vbDefaultButton2 means show Yes and No, use the question icon, and make the second button the default. The constants represent separate settings, so combine one value from each relevant group rather than adding two different button sets together.

Here is a complete example. Before running any macro, save a copy of the workbook: VBA changes cannot be undone with Ctrl+Z. In Excel for Microsoft 365 on Windows, open the VBA editor with Alt+F11, insert a standard module, and place the procedure there. On Mac, the editor shortcut is usually Option+F11; some keyboards require Fn as well.

Sub ConfirmAction()
    Dim answer As VbMsgBoxResult

    ' Ask a clear question and default to No.
    answer = MsgBox("Continue with this action?", _
                    vbYesNo + vbQuestion + vbDefaultButton2, _
                    "Confirm action")

    If answer = vbYes Then
        MsgBox "You chose Yes.", vbInformation, "Choice"
    ElseIf answer = vbNo Then
        MsgBox "No changes were requested.", vbInformation, "Choice"
    End If
End Sub

The line continuation character, a space followed by an underscore, lets VBA split a statement across lines. The answer variable is declared as VbMsgBoxResult, the built-in result type for this function. The example only reports the choice; replace the first response block with the action your macro should take.

Read the Result, Not Just the Caption

MsgBox returns a value indicating which button was pressed. The named constants make the code easier to understand: vbOK is 1, vbCancel is 2, vbAbort is 3, vbRetry is 4, vbIgnore is 5, vbYes is 6, and vbNo is 7.

Compare the returned value with a named constant rather than relying on a number. That makes the intent clearer and reduces the chance of mixing up results. Also, handle every response the chosen set permits. A Yes/No/Cancel prompt has three possible outcomes; code that checks only Yes may accidentally treat Cancel like No, even if those choices should have different consequences.

One common point of confusion is the Cancel button. It returns vbCancel when the selected combination includes that button. It is not interchangeable with No: No is a definite answer, while Cancel usually means stop or leave the operation unchanged.

Set Icons and the Default Button

You can pair a button set with an icon constant. The common choices are vbCritical for a serious error, vbQuestion for a question, vbExclamation for a warning, and vbInformation for an informational message. The icon does not change what the buttons do; it only adds a visual cue. Choose one that supports the message rather than using an alarming icon for routine updates.

The default-button constants are vbDefaultButton1, vbDefaultButton2, vbDefaultButton3, and vbDefaultButton4. They select which available button is initially focused. For a Yes/No prompt that could trigger a consequential action, setting the default to No can help prevent an accidental confirmation. The chosen default must correspond to a button that exists in the selected combination.

For instance, with vbYesNo + vbQuestion + vbDefaultButton2, No is the second button and receives the initial focus. The result still needs to be checked in code; setting the default does not automatically choose it.

When a UserForm Is the Better Choice

A UserForm is the standard VBA approach when you need genuinely custom buttons. In the Visual Basic Editor, choose Insert > UserForm, then add CommandButton controls from the Toolbox. Set each button’s Caption property to the wording you want, such as “Save,” “Discard,” or “Return.” You can also add labels, text boxes, check boxes, and other controls.

Give each button a clear name, such as cmdSave or cmdDiscard, and put its response in that button’s click event. For example, the Save button can validate fields, write values to the workbook, and then close the form. The Discard button can close it without saving. A Cancel button can leave the form open or close it without making changes, depending on the interaction you intend.

Plan the form’s outcome before adding controls. Decide what each button means, whether the form should close after a choice, and how the calling macro will learn the selected action. A common design stores the choice in a public property or variable on the form, then lets the calling procedure inspect it after the form closes. This is more work than a message box, but it gives you control over captions, layout, validation, and behavior.

Common Problems and Practical Limits

  • Using a statement when you need a result: If your code must branch on the choice, assign the function’s return value to a variable. Calling MsgBox only to display a notice is fine when no response is needed.
  • Combining incompatible settings: Include one button-set constant, then add an icon and, if useful, one default-button constant. Do not add vbYesNo and vbOKCancel together expecting four buttons.
  • Assuming button text can be changed: There is no MsgBox argument for custom captions. Use a UserForm instead of trying to infer or alter operating-system dialog labels.
  • Using unclear prompts: “Are you sure?” does not explain what will happen. Say what the action affects, such as “Delete the selected worksheet?” and use a safe default for consequential actions.
  • Forgetting platform limits: VBA macros run in desktop Excel, subject to macro security settings. Excel for the web cannot run or edit VBA macros, although it can open a workbook that contains them. Excel for Mac supports VBA, but Windows-specific API techniques are not automatically portable.

Keep the message concise and make the consequence visible before a destructive action. A message box is not a replacement for validation, backups, or an undo strategy in the macro itself. Since Ctrl+Z does not reverse VBA changes, code that changes or deletes data should be designed and tested carefully.

MsgBox Compared With Other Options

Use MsgBox for a brief notification or a small number of standard responses. It is quick to write, requires no form design, and presents a familiar Windows dialog. Its limitations are equally clear: fixed button captions, fixed layouts, and no room for input controls.

Use InputBox when the user needs to enter a single value in a simple prompt, while keeping in mind that it offers limited control over validation and layout. Use a UserForm when the interface needs custom labels, multiple inputs, or different actions. In Microsoft 365 for Windows, the VBA editor is part of desktop Excel; Excel for the web does not provide a way to run the VBA dialog or form.

There is no separate fee for using the built-in VBA MsgBox function in desktop Excel. A UserForm is also part of VBA and does not require a paid add-in, though designing and maintaining it takes more time. For a workbook shared across platforms, keep the design within standard VBA features and verify that the relevant desktop Excel versions support the workflow.

Frequently Asked Questions

Can I change the text on a VBA MsgBox button?
No. The button captions are fixed by the built-in dialog. Create a UserForm with CommandButton controls if you need custom wording.

How do I show Yes and No buttons in Excel VBA?
Use MsgBox("Your question?", vbYesNo, "Title") and compare the returned value with vbYes or vbNo.

How do I make No the default MsgBox button?
Add vbDefaultButton2 to the buttons argument when No is the second button, as in a Yes/No combination. The user can still select Yes.

Can a MsgBox have three custom buttons?
It can show some predefined three-button combinations, such as Yes/No/Cancel, but it cannot give those buttons custom labels. Use a UserForm for three custom choices.

Does VBA MsgBox work in Excel for the web?
No. Excel for the web cannot run VBA macros. Open the workbook in desktop Excel to run VBA, subject to the workbook’s macro settings.

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.