{"id":12138,"date":"2012-06-05T18:27:02","date_gmt":"2012-06-05T18:27:02","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=1690"},"modified":"2022-08-06T22:59:58","modified_gmt":"2022-08-06T22:59:58","slug":"excel-macro-tutorial-excel-form","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/06\/excel-macro-tutorial-excel-form\/","title":{"rendered":"Excel Macro Tutorial : Excel Form"},"content":{"rendered":"
[et_pb_section fb_built=”1″ _builder_version=”4.16″ global_colors_info=”{}” da_is_popup=”off” da_exit_intent=”off” da_has_close=”on” da_alt_close=”off” da_dark_close=”off” da_not_modal=”on” da_is_singular=”off” da_with_loader=”off” da_has_shadow=”on” da_disable_devices=”off|off|off”][et_pb_row _builder_version=”4.16″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” global_colors_info=”{}”][et_pb_column type=”4_4″ _builder_version=”4.16″ custom_padding=”|||” global_colors_info=”{}” custom_padding__hover=”|||”][et_pb_text _builder_version=”4.16″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” global_colors_info=”{}”]In this article, I am going to explain every aspect of the VBA Form. User forms in Excel are really nice to see. It looks very fascinating while working with User Forms. You can build a very nice UI (User Interface) using Excel VBA Form. In this article, you are going to learn the following things about VBA User Form:<\/strong><\/p>\n <\/font>\n<\/div>\n Creating a Form (Designing a Form) in excel is very easy and interesting. For Designing a Form a single Line Code is not required. Code is required only to make that Form function as per your requirement. Step 4. <\/strong> Right Click on Microsoft Excel Object<\/strong> Step 6. <\/strong> In Right Side you can see one Default UserForm1 Created. You can see the ToolBox as well with all the Controls available for the User Form.<\/p>\n \n<\/a> Step 7. <\/strong> Using the Tool Box of the User Form you can Drag and Drop what all Controls you want on your form. 2. Showing a VBA Form (Display an Excel Form): <\/strong><\/font> As you have seen we have created the User Form in VBA Code. User form will not be displaying on the Excel Sheet by default. To display the form we need to write a piece of code. This is just a single statement to launch an Existing User Form. You can execute that statement to open User form.<\/p>\n You can add the above statement where you want to launch your user form. UserForm1<\/strong> is the name of the User Form Control.<\/p>\n Before getting in to technical details lets discuss, what is Initialization of User form? Initialization of User Form is nothing but to do some default operation while launching the Form. At the time of loading the User Form, we set certain values or any kind of defaulting to any field, comes under Initialization. <\/p>\n \nWhatever code is there in UserForm_Initialize()<\/strong> Event of User Form, will be executed as soon as User Form will be launched (Shown). Like windows dialog box User Form also has a by default Cross Button to close the form. It will simply close the User form. There is a difference between Closing<\/strong> and hiding <\/strong> a user form.<\/p>\n Closing a User form will close the User Form. All the value entered in to that form will be cleared (lost) when you launch it again. Whereas on hiding a user form all the vaues entered in to that form will remain there and can be seen again once you launch the user form again. Both the terms (Closing and hiding) are pretty much self explanatory.\n<\/p>\n Closing or Unloading an Excel User form are same. In VBA Code, to close an Excel Form, Unload<\/strong> keyword is used. This is the reason we call it both either closing a VBA Form or Unloading a VBA Form.\n\t<\/p>\n Now you know the about Closing, Hiding and Unloading an Excel UserForm. Now i will show you the VBA syntax for Unloading (Closing) and Hiding with an Example.\n<\/p>\n Now its time for doing some hands-on. I have created one Simple Data Entry Form using Excel VBA Form as shown below in Image. If you wish to see the Code and the whole Workbook download it from below:<\/p>\n
\n1. How to Create User Form (Creating VBA Form)
\n2. Showing a VBA Form (Display an Excel Form)
\n3. How to Initialize a UserForm
\n4. Hiding a VBA Form
\n5. Unloading VBA Form
\n6. Closing VBA Form
\n7. Example: Creating Data Entry Form using Excel Form
\n8. Free Download: Data Entry Form using Excel Form<\/p>\n1. How to Create User Form (Creating VBA Form)<\/h1>\n
\nTo create a Form, follow the below simple steps:
\n
\nStep 1. <\/strong> Open your Workbook and Press Alt + F11<\/strong>
\nStep 2. <\/strong> VB Code Editor will open as below
\n
\n
\n<\/p>\n
\nStep 5. <\/strong> Go to Insert –> User Form <\/strong>
\n
\n<\/a><\/p>\n
\n<\/p>\n
\nRefer the below User form which I have created to show as an example. You can design by your own how you want.
\n
\n<\/a>
\n<\/p>\n\r\nUserForm1.Show<\/strong>\r\n<\/code>\r\n<\/pre>\n
3. How to Initialize a VBA Form: <\/h1>\n
\nClick on the User Form and you will be taken to the below Private Sub with Initialize Event as shown in Image below:\n<\/p>\n<\/a>\nExample:<\/h3>\n
\r\n\r\nPrivate Sub UserForm_Initialize()\r\n\r\nUserForm1.ComboBox1.Clear\r\n With UserForm1.ComboBox1\r\n .AddItem \"Junior Engineer\"\r\n .AddItem \"Engineer\"\r\n .AddItem \"Team Lead\"\r\n .AddItem \"Technical Lead\"\r\n .AddItem \"Functional Consultant\"\r\n .AddItem \"Technical Consultant\"\r\n .AddItem \"Project Manager\"\r\n .AddItem \"Delivery Manager\"\r\n .AddItem \"Group Delivery Manager\"\r\n .AddItem \"Unit Head\"\r\n .AddItem \"Regional Head\"\r\n End With\r\nEnd Sub\r\n<\/code><\/pre>\n
4. Closing and Hiding and Unloading a VBA Form: <\/h1>\n
\n
\n \n\t\tHiding a User Form: <\/strong><\/font>
\n\t\t\ti) Syntax:<\/strong><\/i>
\n\t\t\t\t<UserForm Name>.Hide
\n\t\t\tii) Example:<\/strong><\/i>
\n\t\t\t\tPrivate Sub UserForm_Click()
\n\t\t\t\t\tUserForm1.Hide
\n\t\t\t\tEnd Sub<\/p>\n<\/td>\n\n<\/a>\n<\/td>\n<\/tr>\n \n \n\t\tUnloading or Closing a User Form: <\/strong><\/font>
\n\t\t\ti) Syntax:<\/strong><\/i>
\n\t\t\t\tUnload <User Form Name> OR<\/strong> Unload Me
\n\t\t\tii) Example:<\/strong><\/i>
\n\t\t\t\tPrivate Sub UserForm_Click()
\n\t\t\t\t\tUnload UserForm1 OR<\/strong> Unload Me
\n\t\t\t\tEnd Sub<\/p>\n<\/td>\n<\/tr>\n<\/table>\n5. Example: Creating Data Entry Form using Excel Form: <\/h1>\n