Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
After adding forms and ActiveX to a worksheet form, you usually want to fine-tune and rearrange the controls in a variety
of ways to create a well-designed, user friendly form. Common tasks include the following:
Controlling the display of gridlines while you work with the controls, and deciding whether to display the gridlines
to the user on the final worksheet form.
Selecting and deselecting controls so that you can specify properties or make additional adjustments.
Editing text in a control, such as the caption or label.
Grouping, copying, moving, and aligning controls to organize the layout of the worksheet form.
Resizing and formatting controls to obtain the appearance that you want.
Positioning or sizing a control with a cell.
Protecting controls and linked cells according to your specific data protection needs.
Enabling or disabling the printing of controls when the worksheet form is printed.
Deleting unused controls.
You can design a worksheet form with or without cell gridlines in the background. For example, you might want to turn off
cell gridlines and then format all the cells with the same color or pattern, or even use a picture as a sheet background. To
hide or show the gridlines, on the View tab, in the Show/Hide group, clear or select the Gridlines check box.
Because there are three different types of controls and objects that you can modify uniquely, you might not know for sure
which type of control it is just by looking at it. To determine the type of control (Form or ActiveX), select and right-click the
control, and then display the shortcut menu:
If the shortcut menu contains the command Properties, the control is an ActiveX control, and you are in design
mode.
If the shortcut menu contains the command Assign Macro, the control is a Form control.
Tip: To display the correct shortcut menu for the group box Form control, make sure that you select the perimeter instead of the interior of
the group box.
If the shortcut menu contains the command Edit Text, the object is a Drawing object.
VBA UserForms
For maximum flexibility, you can create UserForms, which are custom dialog boxes, that usually include one or more
ActiveX controls. You make UserForms available from VBA code that you create in the Visual Basic Editor. The high-level
steps for creating a UserForm are as follows:
1. Insert a UserForm into your workbook's VBAProject. You access a workbook's VBAProject by first displaying the
Visual Basic Editor (press ALT+F11) and then, on the Insert menu, clicking UserForm.
2. Write a procedure to display the UserForm.
3. Add ActiveX controls.
4. Modify properties for the ActiveX controls.
5. Write event-handler procedures for the ActiveX controls.
By using UserForms, you can also utilize advanced form functionality,. For example, you can programmatically add a
separate option button for each letter of the alphabet or you can add a check box for each item in a large list of dates and
numbers.
Before creating a UserForm, consider using built-in dialog boxes available from Excel that might fit your needs. These
built-in dialog boxes include the VBA InputBox and MsgBox functions, the
Excel InputBoxmethod, GetOpenFilename method, GetSaveAsFilename method, and the Dialogs object of
the Application object, which contains all the built-in Excel dialog boxes.