Setting ActiveX Control Properties
Every
ActiveX control has properties, or settings, that determine its
appearance and function. You can open a property sheet that displays all
the settings for that control in alphabetic or category order directly
from Word. The ActiveX controls appear in the Properties window in two
columns: the left column displays the name of the control, and the right
column displays the current value or setting for the control. When you
select either column, a list arrow appears in the right column, allowing
you to select the setting you want. After you set properties, you can
add VBA code to a module to make it perform.
Set ActiveX Control Properties
- Click the Developer tab.
- Click the Design Mode button (highlighted).
- Select the control whose properties you want to modify.
- Click the Properties button.
- To switch controls, click the Controls list arrow (at the top), and then select the one you want.
- Click the Alphabetic or Categorized tab to display the control properties so you can find the ones you want.
- Click the property box for the property you want to modify, and then do one of the following:
- Type the value or information you want to use, such as the control name.
- If the property box contains a list arrow, click the arrow and then click a value in the list.
- If
a property box contains a dialog button (...), click it to open a
dialog box to select options or insert an object, such as a picture.
- When you’re done, click the Close button on the Properties window.
- Click the Design Mode button (not highlighted) to exit.
Adding VBA Code to an ActiveX Control
After
you add controls and set properties, you can add VBA code to a module
to determine how the controls respond to user actions. All controls have
a predefined set of events. For example, a command button has a Click
event that occurs when the user clicks the button. When you select a
control in Design Mode and then click the View Code button, the Visual
Basic Editor opens with a Code window, displaying the start of a
procedure that runs when the event occurs. The top of the Code window
displays the active object and event procedure. The Object list displays
the ActiveX control, such as CommandButton1, and the Procedure list displays the trigger event, such as Click.
Add VBA Code to an ActiveX Control
- Click the Developer tab.
- Click the Design Mode button (highlighted).
- Select the control to which you want to add VBA code.
- Right-click the control, and then click View Code.
The Visual Basic Editor window opens.
- To show the Properties window, click the Properties window button.
- To help with scripting commands, click the Object Browser button on the toolbar.
-
Click in the Code window between the beginning and ending line of the
procedure, and then type VBA code to perform the task you want.
The Object list is set to CommandButton1, and the Procedure list is set to Click.
- When you’re done, click the Save button on the toolbar.
- Click the program Close button.
- Click the Design Mode button (not highlighted) to exit.