Documente Academic
Documente Profesional
Documente Cultură
Print
Show All You can use a button (a Form control) or a command button (an ActiveX control) to run a macro that performs an action when a user clicks it.
Learn about the button and the command button Add a button (Form control) Add a command button (ActiveX control)
TOP OF PAGE
2.
On the Developer tab, in the Controls group, click Insert, and then under Form Controls, click Button
3. 4. 5.
Click the worksheet location where you want the upper-left corner of the button to appear. Assign a macro to the button. To specify the control properties of the button, right-click the button, and then click Format Control.
TOP OF PAGE
2.
On the Developer tab, in the Controls group, click Insert, and then under ActiveX Controls, click Command Button
3. 4.
Click the worksheet location where you want the upper-left corner of the command button to appear. In the Controls group, click View Code. This starts the Visual Basic Editor. Make sure that Click is selected in the dropdown list on the right. The sub procedure called CommandButton1_Click, as shown in the following picture, runs two macros when the button is clicked: SelectC15 and HelloMessage.
5.
In the sub procedure for the command button, do one of the following:
Type the name of an existing macro in the workbook. You can find macros by clicking Macros in the Code group. You can run multiple macros from a button by typing the macro names on separate lines inside the sub procedure. Type your own VBA code. The Properties box appears. For detailed information about each property, select the property, and then press F1 to display a Visual Basic Help topic. You can also type the property name in the Visual Basic Help Search box. The following table summarizes the properties that are available.
The way the control is attached to the cells below it (free floating, move but do not size, or move Placement (Excel) and size). Whether the control can be printed. Whether the control is visible or hidden. Text: Font attributes (bold, italic, size, strikethrough, underline, and weight). Bold, Italic, Size, StrikeThrough, Underline, Weight (Form) Caption (Form) WordWrap (Form) PrintObject (Excel) Visible (Form)
Descriptive text on the control that identifies or describes it. Whether the contents of the control automatically wrap at the end of a line. Size and Position: Whether the size of the control automatically adjusts to display all the contents. The height or width in points. The distance between the control and the left or top edge of the worksheet. Formatting: The background color. The background style (transparent or opaque). The foreground color.
Whether the control has a shadow. Image: The bitmap to display in the control. The location of the picture relative to its caption (left, top, right, and so on). Keyboard and Mouse: The shortcut key for the control. A custom mouse icon. The type of pointer that is displayed when the user positions the mouse over a particular object (standard, arrow, I-beam, and so on). Whether the control takes the focus when clicked.
Shadow (Excel)
TakeFocusOnClick (Form)