VBA MsgBox Text Formatting: Lines, Buttons, and Limits

VBA & macros · Updated November 18, 2026

VBA’s MsgBox can display plain text, line breaks, tabs, a title, and built-in buttons and icons, but it cannot apply rich text styling such as bold, colored words, or different fonts within the message. To control the layout, build the prompt string with constants such as vbCrLf and pass it to MsgBox; for genuinely styled content, use a UserForm instead.

What text formatting MsgBox supports

A standard message box is designed for a short prompt and a response, not for laying out a document. Its prompt is plain text. You can arrange that text across lines and add spacing, and you can choose a window title, button set, and standard icon. The operating system and Office version determine the dialog’s appearance, so the same VBA call may look slightly different on another computer.

For example, a prompt can show a heading-like first line followed by details, but the heading is still ordinary text. It cannot be independently bolded or enlarged. Likewise, a message cannot contain a clickable hyperlink or a button with a custom label just by adding special characters to the prompt.

  • Supported: line breaks, tabs, ordinary characters, a title, standard button combinations, and standard icons.
  • Not supported within the prompt: rich text, custom fonts, per-word color, images, custom button captions, and interactive controls.

Adding line breaks and spacing

Join pieces of text with vbCrLf to start a new line. This is often the clearest choice for a Windows Excel macro. vbNewLine is another VBA constant for a newline; using a named constant makes the intent clearer than manually inserting control characters. A blank line is made by inserting two line breaks between sections.

For example, with the first line used as a brief heading and the following lines used for details, construct the prompt like this:

Sub ShowFormattedMessage()
    Dim prompt As String

    ' Separate the heading and details with a blank line.
    prompt = "Import check" & vbCrLf & vbCrLf & _
             "The source file is ready." & vbCrLf & _
             "Select OK to continue."

    MsgBox prompt, vbInformation, "Import"
End Sub

In this example, the first argument is the complete prompt, vbInformation selects the standard information icon, and Import is the dialog title. The line breaks affect only the prompt; they do not change the title or the buttons.

Use vbTab when you need a simple horizontal gap, such as between a label and a value. Tabs are not a dependable way to create perfectly aligned columns: the dialog uses a proportional font and tab stops may not line up as expected. For data with several columns, a worksheet range or a UserForm with labels is more suitable.

Choosing a title, buttons, and icon

The MsgBox function accepts arguments in this order: prompt, buttons, title, help file, and help context. Most Excel macros need only the first three. The Buttons argument can combine constants for a button set, an icon, and the default button. Use VBA’s named constants instead of unexplained numeric values, because the names make the dialog’s behavior easier to read and maintain.

Common button constants include vbOKOnly, vbOKCancel, vbYesNo, and vbYesNoCancel. Icons include vbInformation, vbExclamation, vbQuestion, and vbCritical. For instance, vbYesNo Or vbQuestion requests Yes and No buttons with the question icon. A default-button constant such as vbDefaultButton2 can be combined with those choices.

The choice of buttons should match what the code can actually do. A message that only reports a completed task usually needs vbOKOnly. A prompt asking permission to continue can use Yes and No, then inspect the returned value. The function returns a value such as vbYes, vbNo, or vbCancel; it does not return the displayed prompt text.

Example: ask before continuing

This example creates a multi-line confirmation message and uses the response to decide whether to continue. The default button is No, which is a cautious choice when the action should not happen unless the user explicitly agrees.

Sub ConfirmImport()
    Dim prompt As String
    Dim answer As VbMsgBoxResult

    prompt = "Import the selected file?" & vbCrLf & vbCrLf & _
             "Existing records will be checked for duplicates."

    answer = MsgBox(prompt, vbYesNo Or vbQuestion Or vbDefaultButton2, _
                    "Confirm import")

    If answer = vbYes Then
        ' Place the import procedure here.
        MsgBox "The import can proceed.", vbInformation, "Ready"
    Else
        MsgBox "No changes were requested.", vbInformation, "Cancelled"
    End If
End Sub

The VbMsgBoxResult declaration makes clear that answer stores a message-box response. The example does not perform an import by itself; the comment marks where the relevant procedure would go. If you adapt the code to change workbook data, save a copy of the workbook before running the macro. VBA actions cannot be reversed with Ctrl+Z.

Can you make selected words bold or colored?

No. A common misconception is that adding HTML tags such as <b>, Markdown markers, or formatting codes to the prompt will style the message. Those characters are not interpreted as rich formatting by MsgBox; they appear as text or are handled as ordinary characters. The prompt has no setting for font size, bold, italics, foreground color, or background color.

You can make plain-text structure easier to scan by keeping the wording concise, putting the key instruction first, separating sections with blank lines, and using simple labels such as Status: or Next step:. Avoid using rows of spaces to simulate alignment, because font metrics and dialog sizing can differ between systems. Also avoid excessive capitalization or decorative characters that make a warning harder to read.

When a UserForm is the better option

If the requirement includes styled text, custom buttons, a logo, a list, or several fields, a VBA UserForm gives you much more control than a message box. In the Visual Basic Editor, a form can contain labels, command buttons, text boxes, and other controls. A label’s properties can be configured for visual presentation, and separate labels can use different fonts or colors. A UserForm can also respond to user actions without forcing all interaction into the limited set of standard message-box buttons.

That flexibility comes with extra work. You must create and maintain the form, set its controls and properties, and write event procedures for actions such as clicking a button. For a one-line status or a simple Yes/No question, MsgBox is usually simpler and less error-prone. For a multi-step choice or a branded interface, the extra setup may be worthwhile.

For information that users may need to revisit, consider putting the details in a worksheet, a report, or a file rather than placing a long explanation in a transient dialog. A message box can interrupt a workflow, and users may dismiss it before they have recorded its contents.

Common problems and practical fixes

  • Line breaks do not appear: Check that vbCrLf is concatenated into the prompt string and that the complete string is passed as the first argument. A line break written outside the string without concatenation will cause a VBA syntax error.
  • The message is hard to read: Shorten the prompt and divide it into meaningful lines. The message box chooses its own size and may wrap long lines differently on different displays.
  • The wrong button is selected: Confirm that the constants in the buttons argument describe the intended button set and default. Then compare the returned value with constants such as vbYes, not with the button’s displayed caption as text.
  • Special characters look different: The display depends on the selected font, operating system, and available characters. Keep important instructions in standard characters if the workbook will be used on varied computers.
  • The title is blank or unexpected: Remember that title is the third argument. If you omit the buttons argument but want to supply a title, use the appropriate argument position rather than placing the title second.

When diagnosing a dialog, inspect the assembled prompt in the VBA editor or temporarily assign it to a string variable before calling MsgBox. This separates problems in string construction from choices about buttons and icons. If the prompt is assembled from cell values, check for empty cells, unexpected spaces, or values that make the message much longer than intended.

Excel for Windows and Mac

The VBA MsgBox function is available in Excel for Microsoft 365 on Windows and in Excel for Mac, but the dialog’s native appearance can vary by operating system. Button spacing, fonts, and wrapping should not be treated as pixel-perfect design. vbCrLf is widely used in VBA prompts; avoid relying on exact dialog dimensions or on tab spacing for layout if the workbook is shared across platforms.

The examples use standard VBA syntax and do not require an Excel worksheet function. If you distribute a macro-enabled workbook, recipients must be able to run macros under their organization’s security settings. A message box does not bypass macro security, and its formatting options do not affect whether a macro is trusted or permitted to run.

Frequently Asked Questions

How do I put a new line in a VBA MsgBox?
Concatenate the text with vbCrLf, for example "First line" & vbCrLf & "Second line". Use two line breaks if you want a blank line between sections.

Can I bold one word in a VBA MsgBox?
No. A standard message box displays plain prompt text and does not support partial bold, italics, colors, or font changes. Use a UserForm if those visual controls are necessary.

How do I change the MsgBox title?
Pass the title as the third argument: MsgBox "Saved", vbInformation, "Workbook status". The second argument is the buttons and icon setting.

Can I customize the button text?
No. MsgBox provides standard button sets with standard captions. Create a UserForm with command buttons if you need labels such as “Save changes” or “Open report.”

How do I check which button the user clicked?
Store the function result in a variable, then compare it with a result constant. For example, a Yes/No dialog can be tested with If answer = vbYes Then.

Can MsgBox display a long report neatly?
It can show multi-line plain text, but it is not a report viewer and its wrapping and size are controlled by the system. Keep the prompt brief or show detailed information in a worksheet, file, or UserForm.

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.