VBA: Multiline Textbox

VBA - Visual Basic for Application

If you work a lot with Microsoft Office, you can use VBA to make many tasks easier. Sometimes you need to fetch the content of a website and sometimes you need a multiline textbox in a VBA form (UserForm) to enter user data.

Screenshot of a multiline textbox in VBA UserForm
Example of a textbox with line break

The example here shows a userform with a textbox that automatically wraps when the text exceeds the width of the text box.

This is achieved by setting the Multiline Property to True.

Screenshot VBA Editor Properties Set Multiline to True
Set Multiline property to True

Enter does not work with multiline textbox

The problem is that this only happens automatically. You can’t use the Enter or Return key to force the line break when writing. As it is shown in the following example picture, it does not work for the time being.

Screenshot VBA textbox with line break by Enter key
Line breaks created with Enter/Return key

To do this, we need to adjust another property of the text box. As shown in the image below, we need to set the EnterKeyBehavior property to True.

Screenshot VBA Editor Properties Set EnterKeyBehavior to True
Set property EnterKeyBehavior to True

In combination with Multiline True you can insert line breaks as shown above.

More detailed explanations of the Multiline Property can be found on the Microsoft website.

Leave a Reply

Your email address will not be published. Required fields are marked *