{"id":17100,"date":"2021-11-01T21:21:39","date_gmt":"2021-11-01T20:21:39","guid":{"rendered":"https:\/\/ekiwi-blog.de\/?p=17100"},"modified":"2022-05-25T12:24:34","modified_gmt":"2022-05-25T11:24:34","slug":"vba-multiline-textbox","status":"publish","type":"post","link":"https:\/\/ekiwi-blog.de\/en\/17100\/vba-multiline-textbox\/","title":{"rendered":"VBA: Multiline Textbox"},"content":{"rendered":"<p>If you work a lot with <em>Microsoft Office<\/em>, you can use <abbr title=\"Visual Basic for Application\">VBA<\/abbr> to make many tasks easier. Sometimes you need to <a href=\"https:\/\/ekiwi-blog.de\/en\/24062\/vba-get-data-from-website\/\">fetch the content of a website<\/a> and sometimes you need a <strong>multiline textbox<\/strong> in a VBA form (UserForm) to enter user data.<\/p>\n<figure id=\"attachment_17093\" aria-describedby=\"caption-attachment-17093\" style=\"width: 306px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-userform-multiline-textbox.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-17093 size-full\" title=\"Example textbox with line break when text reaches the width of the text box\" src=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-userform-multiline-textbox.png\" alt=\"Screenshot of a multiline textbox in VBA UserForm\" width=\"306\" height=\"233\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-userform-multiline-textbox.png 306w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-userform-multiline-textbox-300x228.png 300w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/a><figcaption id=\"caption-attachment-17093\" class=\"wp-caption-text\">Example of a textbox with line break<\/figcaption><\/figure>\n<p>The example here <a title=\"VBA code open form in microsoft office (excel, word)\" href=\"https:\/\/ekiwi-blog.de\/en\/17115\/vba-function-to-open-a-form-userform-in-microsoft-office\/\">shows a userform<\/a> with a textbox that automatically wraps when the text exceeds the width of the text box.<\/p>\n<p>This is achieved by <strong>setting the Multiline Property to True<\/strong>.<\/p>\n<figure id=\"attachment_17095\" aria-describedby=\"caption-attachment-17095\" style=\"width: 182px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-multiline.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-17095 size-full\" title=\"If Multiline equals True, then an ordinary line break occurs\" src=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-multiline.png\" alt=\"Screenshot VBA Editor Properties Set Multiline to True\" width=\"182\" height=\"581\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-multiline.png 182w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-multiline-94x300.png 94w\" sizes=\"auto, (max-width: 182px) 100vw, 182px\" \/><\/a><figcaption id=\"caption-attachment-17095\" class=\"wp-caption-text\">Set Multiline property to True<\/figcaption><\/figure>\n<h2>Enter does not work with multiline textbox<\/h2>\n<p>The problem is that this only happens automatically. You can&#8217;t use the <a href=\"https:\/\/ekiwi-blog.de\/en\/49525\/entering-the-at-sign-on-the-english-keyboard\/\">Enter<\/a> 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.<\/p>\n<figure id=\"attachment_17097\" aria-describedby=\"caption-attachment-17097\" style=\"width: 306px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/enter-key-not-working-vba-textbox.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-17097 size-full\" title=\"Problem Enter\/Return key does not work with textbox in VBA\" src=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/enter-key-not-working-vba-textbox.png\" alt=\"Screenshot VBA textbox with line break by Enter key\" width=\"306\" height=\"233\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/enter-key-not-working-vba-textbox.png 306w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/enter-key-not-working-vba-textbox-300x228.png 300w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/a><figcaption id=\"caption-attachment-17097\" class=\"wp-caption-text\">Line breaks created with Enter\/Return key<\/figcaption><\/figure>\n<p>To do this, we need to adjust another property of the text box. As shown in the image below, we need to <strong>set the EnterKeyBehavior property to True<\/strong>.<\/p>\n<figure id=\"attachment_17099\" aria-describedby=\"caption-attachment-17099\" style=\"width: 183px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-enter-key-behavior-Kopie.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-17099 size-full\" title=\"EnterKeyBehavior to True and MultiLine to True\" src=\"http:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-enter-key-behavior-Kopie.png\" alt=\"Screenshot VBA Editor Properties Set EnterKeyBehavior to True\" width=\"183\" height=\"536\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-enter-key-behavior-Kopie.png 183w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/textbox-property-enter-key-behavior-Kopie-102x300.png 102w\" sizes=\"auto, (max-width: 183px) 100vw, 183px\" \/><\/a><figcaption id=\"caption-attachment-17099\" class=\"wp-caption-text\">Set property EnterKeyBehavior to True<\/figcaption><\/figure>\n<p>In combination with Multiline True you can insert line breaks as shown above.<\/p>\n<p>More detailed explanations of the Multiline Property can be found on the <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/vba\/api\/outlook.textbox.multiline\">Microsoft website<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>If you work a lot with Microsoft Office, you can use VBA to make many tasks easier. Sometimes you need<\/p>\n","protected":false},"author":2,"featured_media":13630,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1555],"tags":[1701,1702,1703,1858,1704,1860,1700,1705,1861,1706,1862],"class_list":["post-17100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-en","tag-access-en","tag-excel-en","tag-microsoft-en","tag-microsoft-office-en-2","tag-microsoft-office-en","tag-programmierung-en","tag-programming","tag-vba-en","tag-vba-en-2","tag-visual-basic-for-application-en","tag-visual-basic-for-application-en-2"],"_links":{"self":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/17100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/comments?post=17100"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/17100\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media\/13630"}],"wp:attachment":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media?parent=17100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/categories?post=17100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/tags?post=17100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}