Message Box Generator

This Site generates Code for the MsgBox function used in VBScript and VBA, or for the MessageBox(A/W) API functions. You can hover over most titles to get some help.
Note that this application will not stop you from making invalid choices, for example selecting default button 3 when only one button is present. This Windows API call is fairly tolerant towards invalid combinations.

To decode a message box option number, click here

Title
Body
Buttons

Titlebar [X] Button: Auto
Default Button
Icon (Aliases in Parenthesis)

From the API Documentation: The question-mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.

More Options







About Marked Options

Options marked with an Asterisk are not mentioned in the MsgBox documentation. They are listed because the underlying API call to MessageBox(A/W) documents them, which makes them valid choices.

Example

Title
Body

Command (VBA/VB Script)

MsgBox "Body",0,"Title"

Save this to a file with extension .vbs or paste it into a VBA macro.

Command (Windows API, C style)

MessageBox(hWnd,"Body","Title",0);

Replace hWnd with your current window handle, or use NULL if no window is present.

Return Value

The return value is an integer representing the pressed button:
  • 1: OK
  • 2: Cancel
  • 3: Abort
  • 4: Retry
  • 5: Ignore
  • 6: Yes
  • 7: No
  • 10: Try Again
  • 11: Continue

Escape key

Users can close the dialog using the ESC key if either a "Cancel" button is present, or the dialog contains only an "OK" button. The returned value from the dialog function is the respective button code.

Official Documentation

(VBA) MsgBox Function
(API) MessageBox Function
Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 3.149.251.26