No: VBA’s built-in MsgBox has no setting or argument that adds a scrollbar. For long text, use a VBA UserForm with a multiline TextBox configured for vertical scrolling, or present the content on a worksheet where it can be read and navigated more freely.
Why a VBA MsgBox cannot scroll
MsgBox displays a standard Windows message dialog. Its arguments let you supply a prompt, choose buttons and an icon, set a title, and optionally specify help information. They do not expose the dialog’s layout or add a scrollable text area. There is no supported setting such as a “scroll” option that turns a message box into a scrolling window.
Windows and Excel may size a message box to fit some text, but that does not make it a dependable viewer for lengthy content. The dialog’s appearance and available space depend on factors such as display scaling, screen size, and the operating system. If the text is too long or awkwardly formatted, users may have trouble reading it. A scrollbar is not something the VBA MsgBox function can provide.
This distinction matters because a message box is designed for a brief notice or a simple decision, not for displaying a report, a long error explanation, or pages of instructions. Adding more line breaks can improve readability, but it does not add scrolling.
What MsgBox does support
A message box is useful when the user needs a short prompt and a small set of choices. For example, a macro can ask whether to continue before making a change. The function returns a value corresponding to the button chosen, so VBA can respond to that choice. Its optional button and icon settings change the dialog’s controls, not the way its message text is navigated.
Use MsgBox when the message fits comfortably in a compact dialog. Common appropriate uses include:
- Confirming a simple action, such as whether to continue.
- Reporting a brief completion message or a concise error.
- Showing a short instruction before a macro proceeds.
If the reader needs to inspect a lot of text, copy particular passages, or scroll back and forth, choose a different interface rather than trying to stretch the message box beyond its purpose.
Line breaks help, but do not create scrolling
You can format a prompt with VBA’s vbCrLf constant to put text on separate lines. This is helpful for short, structured messages—for example, a few totals or a brief list of warnings. It does not make the dialog’s text area scrollable, and it does not guarantee that a long prompt will fit on the user’s screen.
For example, a short message can be assembled with line breaks like this:
Dim promptText As String
' Separate two brief statements with a line break.
promptText = "The import is complete." & vbCrLf & "Rows added: 12"
MsgBox promptText, vbInformation, "Import status"
This is suitable for a compact status update, not for a long list of records. If your message contains many paragraphs, hundreds of lines, or details the user may need to review while working, use a UserForm or a worksheet instead. Splitting the text across a chain of message boxes is possible, but it makes navigation cumbersome: users must dismiss each dialog, and they cannot easily move through the whole message as one document.
Use a UserForm for a scrollable message
A VBA UserForm gives you control over the window and its controls. Put a TextBox on the form, set it to accept multiple lines, and enable its vertical scrollbar. Then assign the long message to the TextBox. Users can scroll through the text without closing one dialog and opening another.
In the Visual Basic Editor in desktop Excel for Windows, create a UserForm and set its (Name) property to frmScrollableMessage. Add a TextBox named txtMessage and a CommandButton named cmdClose. In the TextBox Properties window, set:
MultiLinetoTrue.ScrollBarsto2 - fmScrollBarsVertical.WordWraptoTrue, so long lines wrap within the control.LockedtoTrueif readers should not edit the text. They can still select text in a locked TextBox in the usual form-control interaction.
Size the TextBox to occupy most of the form, leaving room for the Close button. A scroll bar is useful only if the control has a constrained visible area; making it as tall as the entire message defeats the purpose. If users need to copy passages, check that selecting text works as expected with the control’s other properties.
Example code for showing long text
Put the following procedures in the UserForm’s code module. The public procedure accepts the message, and the button closes the form. Change the control names in the code if you chose different names in the Properties window.
Public Sub SetMessage(ByVal messageText As String)
' Put the supplied text into the scrollable TextBox.
Me.txtMessage.Value = messageText
End Sub
Private Sub cmdClose_Click()
' Close the form when the user clicks Close.
Unload Me
End Sub
Then put this procedure in a standard module. The example creates a message with enough lines to demonstrate why a scrollable control can be preferable. Replace the sample wording with the information your macro needs to display.
Before running a macro, save a copy of the workbook. VBA macros cannot be undone with Ctrl+Z, and saving the file as a macro-enabled workbook (.xlsm) preserves its VBA project.
Public Sub ShowLongMessage()
Dim messageText As String
Dim messageForm As frmScrollableMessage
' Build sample text with line breaks.
messageText = "Review these items before continuing:" & vbCrLf & _
"1. Confirm the source file." & vbCrLf & _
"2. Check the imported column headings." & vbCrLf & _
"3. Verify the totals against the source." & vbCrLf & _
"Add more lines here if the notice needs them."
' Create the form, load its text, and show it as a dialog.
Set messageForm = New frmScrollableMessage
messageForm.SetMessage messageText
messageForm.Show vbModal
Set messageForm = Nothing
End Sub
vbModal means the user must close the form before returning to the code that displayed it. That is often appropriate for a notice that must be read first. If the message is reference material that users should consult while interacting with the workbook, a modeless form may suit the task better, but the macro should be designed with that interaction in mind.
Other ways to present lengthy information
A UserForm is not the only alternative. Choose the display method based on what readers need to do with the information, not merely on how many characters it contains.
- Worksheet: Put detailed results or instructions in cells, with headings and appropriate column widths. Users can scroll the sheet, select text, and keep the information alongside workbook data.
- Text file: For a generated log or diagnostic report, write the details to a text file and tell the user where it was saved. This is more practical than filling a dialog with a large log.
- Several concise prompts: Use separate message boxes only when the content naturally divides into a few short stages or decisions. Do not use a long sequence as a substitute for a document.
- UserForm with additional controls: Add buttons, labels, or tabs if readers need to choose among actions or view related categories. Keep the main text area large enough to read.
An InputBox is not a scrollable-message solution. It is intended to collect a short user entry, not to display a long read-only explanation. Likewise, changing the MsgBox title or icon affects presentation but cannot provide a scrollbar.
Common problems and compatibility notes
If a UserForm’s scrollbar does not appear or the text is hard to read, check the TextBox properties first. It must be multiline, and its ScrollBars property must be set to vertical or both. Confirm that the TextBox is not so tall that all the text fits in its visible area. With WordWrap turned off, a long line may require horizontal scrolling or be inconvenient to inspect; turn wrapping on when the text is prose.
Also check the actual control name and the form’s name. The sample declares a variable of type frmScrollableMessage; that name must match the UserForm’s (Name) property, not merely its displayed caption. The TextBox and button names used in the form code must match their own (Name) properties too. A mismatch can produce a compile error or a “method or data member not found” error.
This guidance concerns VBA in desktop Excel. Excel for the web does not run VBA macros, so a UserForm-based solution will not work there. Excel for Mac supports VBA, but the interface and control behavior can differ from Windows. If a workbook must run on both platforms, test the form on each target version and avoid Windows-only API tricks. A standard UserForm and ordinary MSForms controls are a more portable direction than attempting to alter the native message-box window.
It is possible to find code online that uses Windows API calls to modify or subclass a message box. Such techniques are not a built-in MsgBox feature, can be sensitive to Windows version and 32-bit versus 64-bit declarations, and may destabilize Excel if implemented incorrectly. They are usually a poor trade-off for ordinary workbook messages. A UserForm is easier to maintain and gives you a real scrollable control.
Frequently Asked Questions
Can I add a scrollbar to VBA MsgBox?
No. The built-in MsgBox function has no argument or property for a scrollbar. Use a multiline TextBox on a UserForm or display the long content on a worksheet.
Does vbCrLf make a MsgBox scroll?
No. vbCrLf inserts a line break. It can make a short prompt clearer, but it does not add scrolling or make a long dialog reliably fit on every screen.
Can I make a MsgBox larger to show all the text?
Not through the supported VBA MsgBox arguments. Its size is managed by the system rather than by a width or height parameter in the function. Use a form when you need control over the display area.
How do I show a long message in Excel VBA?
Create a UserForm with a multiline TextBox, set ScrollBars to vertical, and assign the message to the control. For reports or logs, a worksheet or text file may be a better reading surface.
Will a VBA UserForm work in Excel for the web?
No. Excel for the web does not execute VBA macros or display VBA UserForms. Users need desktop Excel to run this kind of VBA solution.
Related
- Data Validation Studio: Excel Rules, Setup, and Limits
- Power Query Circular Reference: Causes and Fixes
- Excel Data Validation Source: Lists, Ranges, and Rules
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Assign String to Variable: Syntax and ExamplesTo assign text to a VBA variable, declare it as a string with Dim and use the equals…
- Excel Goal Seek VBA Code for a Whole ColumnTo run Goal Seek down a column, loop through the populated rows and call Range.GoalSeek once per row:…
- Excel Macro Arrays: How VBA Arrays WorkAn Excel macro array is a VBA variable that holds multiple values, so a macro can work with…
- Access VBA Date Conversion: Parse, Format, and ValidateIn Access VBA, use CDate to convert a value VBA already recognizes as a date, DateSerial to build…
- Excel VBA Range Find Exact Match with xlWhole ExplainedTo find a cell whose entire contents match a value in Excel VBA, call Range.Find with LookAt:=xlWhole, and…
- VBA Copy and Paste Values Into the Next Empty Row in ExcelTo copy a range as values into the next empty row in Excel, assign the source range’s .Value…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.