{"id":17115,"date":"2021-11-02T19:32:27","date_gmt":"2021-11-02T18:32:27","guid":{"rendered":"https:\/\/ekiwi-blog.de\/?p=17115"},"modified":"2021-11-14T10:55:11","modified_gmt":"2021-11-14T09:55:11","slug":"vba-function-to-open-a-form-userform-in-microsoft-office","status":"publish","type":"post","link":"https:\/\/ekiwi-blog.de\/en\/17115\/vba-function-to-open-a-form-userform-in-microsoft-office\/","title":{"rendered":"VBA function to open a form (UserForm) in Microsoft Office"},"content":{"rendered":"<p>If you want to simplify your daily work with <abbr title=\"Visual Basic for Application\">VBA<\/abbr> scripts, you can also create one or the other form (<em>UserForm<\/em>) to process user input and user interactions.<\/p>\n<figure id=\"attachment_17116\" aria-describedby=\"caption-attachment-17116\" style=\"width: 533px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-open-userform-in-microsoft-office.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-17116 size-full\" title=\"example opened form using button and macro in Excel\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-open-userform-in-microsoft-office.png\" alt=\"screenshot open UserForm in Excel via button and macro\" width=\"533\" height=\"473\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-open-userform-in-microsoft-office.png 533w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/vba-open-userform-in-microsoft-office-300x266.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/a><figcaption id=\"caption-attachment-17116\" class=\"wp-caption-text\">Example open form with multiline textbox via button in Excel spreadsheet<\/figcaption><\/figure>\n<p>If you want to start such a <em>UserForm, <\/em>e.g. with <a title=\"VBA Textbox line break with enter key or automatically word wrap\" href=\"https:\/\/ekiwi-blog.de\/en\/17100\/vba-multiline-textbox\/\">multiline textbox<\/a>, from an Excel, Word or Microsoft Office application, you have to use the correct function.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of content<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ekiwi-blog.de\/en\/17115\/vba-function-to-open-a-form-userform-in-microsoft-office\/#DoCmdOpenForm_does_not_work\" >DoCmd.OpenForm does not work<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ekiwi-blog.de\/en\/17115\/vba-function-to-open-a-form-userform-in-microsoft-office\/#VBA_code_to_display_the_UserForm\" >VBA code to display the UserForm<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"DoCmdOpenForm_does_not_work\"><\/span>DoCmd.OpenForm does not work<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Because in the Internet it is often recommended to open a created form with the code.<\/p>\n<pre><code>DoCmd.OpenForm \"MyUserFormName\"<\/code><\/pre>\n<p>But this is apparently only meant for Access and brings a debug error with Excel, Word and Co.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"VBA_code_to_display_the_UserForm\"><\/span>VBA code to display the UserForm<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to display a previously created form via an <a href=\"https:\/\/ekiwi-blog.de\/en\/50316\/vba-excel-macro-save-spreadsheet-as-csv-file\/\" title=\"VBA Excel Macro: Save spreadsheet as CSV file\">Excel macro<\/a> or Word macro, you have to use the routine <strong>Show<\/strong>. To do this, one uses the form name and calls the <em>Show<\/em> method.<\/p>\n<pre><code>MyUserFormName.Show<\/code><\/pre>\n<p>So you can then include this line of code in a <em>Macro Sub<\/em> and link the <a title=\"change font size of vba commandbutton\" href=\"https:\/\/ekiwi-blog.de\/en\/17232\/vba-button-change-font-size\/\">button<\/a> to the macro to display the form.<\/p>\n<figure id=\"attachment_17118\" aria-describedby=\"caption-attachment-17118\" style=\"width: 508px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/userform-show-makro-vba-editor-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-17118 size-full\" title=\".Show method to open the userform\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/userform-show-makro-vba-editor-2.png\" alt=\"Screenshot VBA editor with UserForm.Show statement to open a form\" width=\"508\" height=\"333\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/userform-show-makro-vba-editor-2.png 508w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2021\/11\/userform-show-makro-vba-editor-2-300x197.png 300w\" sizes=\"auto, (max-width: 508px) 100vw, 508px\" \/><\/a><figcaption id=\"caption-attachment-17118\" class=\"wp-caption-text\">Example Open form via button in Excel spreadsheet<\/figcaption><\/figure>","protected":false},"excerpt":{"rendered":"<p>If you want to simplify your daily work with VBA scripts, you can also create one or the other form<\/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":[1711,1702,1708,1707,1704,1569,1700,1709,1705,1706,1710],"class_list":["post-17115","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-en","tag-automation-en","tag-excel-en","tag-form","tag-macro","tag-microsoft-office-en","tag-outlook-en","tag-programming","tag-userform","tag-vba-en","tag-visual-basic-for-application-en","tag-word-en"],"_links":{"self":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/17115","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=17115"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/17115\/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=17115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/categories?post=17115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/tags?post=17115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}