VBA for Excel 2007 tutorial-Form


Form is an important part of graphical user interface. It is able to increase interactivities between the users and the software. Microsoft Excel also allows developers to create forms and use them in their programs. Other controls such as text boxes, labels, option buttons, check boxes, dropdown lists that act as components of the form need to be placed on the form to perform their functions by attaching VBA code to them.

VBA for Excel: Using Form

VBA for Excel: Creating form

-Creating a form in Excel 2007

In Excel 2007, you can create a form by selecting UserForm as you have seen in the picture above.

-Setting up form properties

After creating a form you can set its properties such as Name, BackColor, BorderStyle, Caption through the form properties window. To show the form property window, you can press F4 or click Properties Window in the ribbon menu.

VBA for Excel: Form properties windows. Setting form properties.

   The common properties of the form are Name, BackColor, BorderStyle, Caption, Picture, and ScrollBars.
   -Name: The Name property defines the name of the form. The default name of the form is UserForm1, or UserForm2, UserForm3,etc. You can change the name form by editing the default name. By setting the name of the form, you will find it easy to refer to the form in VBA code.
   -BackColor: You can use the BackColor property to set the background color of the form based on the color value that you like.
   -BorderStyle: By setting BorderStyle property to 0-fmBorderStyleNone, the form will display without border. However, if you want to display the form with border you can choose 1-fmBorderStyleSingle.
  -Caption: The Caption property gives the users more information about what you want to form to play the role. For example, if the form is about information of students, you may set the Caption property to Student Information or Student Form.
   -Picture: If you want to display a picture as the background of the form, You need to used the Picture property that allows you to select a picture of your choice. This Picture can be used in conjunction with the PictureSizeMode property to determine whether you want to display the picture in stretch mode, zoom mode, or clip mode.
  -ScrollBars: If there are a lot of information on the form that the user finds hard to see all information, you need to used the ScrollBars. By using the ScrollBars property, your form can be scrolled vertically or horizontally. You can choose one of the ScrollBars values:
     +0-fmScrollBarsNone to disable scroll bars on the form.
     +1-fmScrollBarsHorizontal to show only horizontal scroll bar.
     +2-fmScrollBarsVertical to show only vertical scroll bar.
     +3-fmScrollBarsBoth to show both horizontal and vertical scroll bars.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.