MsgBox
Displays a dialog box and can return which button the user clicked.
response = MsgBox(prompt, buttons, title)This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.
What it does
Overview
Displays a dialog box and can return which button the user clicked.
MsgBox is useful for simple confirmations, warnings, and quick diagnostics while building workbook automation. It is convenient for low-friction user prompts, but it becomes a poor choice once a macro needs structured forms or repeated input.
Quick reference
Syntax
response = MsgBox(prompt, buttons, title)
Inputs
Parameters
See it in practice
Examples
Confirm before overwriting a report
If MsgBox("Overwrite the existing report?", vbYesNo + vbQuestion, "Weekly refresh") = vbYes Then
Call RefreshReport
End IfUse the return value to gate destructive workbook actions.
Debug faster
Common Errors
LogicError
Cause: Showing a prompt but ignoring the returned button value.
Fix: Store or compare the return value when the user's choice matters.
Runtime support
Compatibility
Common questions
Frequently Asked Questions
Displays a dialog box and can return which button the user clicked.
prompt: Message shown to the user. buttons: Optional button and icon combination. title: Optional dialog title.
LogicError: Store or compare the return value when the user's choice matters.