709-218-7927 The Landfall Garden House 60 Canon Bayley Road Bonavista, Newfoundland CANADA A0C 1B0 |
---|
Command Buttons
Small applications can be started by the user with the click of a button. Assuming that we already have a macro that should be activated from a button, let's go about the process of setting up the button.
Creating a Button:
In the host document, choose to view the toolbar "Control Toolbox".
Click on the Command Button tool and drag the default button to a suitable location in your document.
Assigning a Macro to the Button:
This is done automatically by Word97!
Left-click on the button to select it, then right-click and choose View Code from the pop-up menu.
You should be taken into VBE where you will see a short module
Private Sub CommandButton1_Click() End Sub
You are now in a position to place within this macro skeleton a call to your existing code, or to rename the module, and so on.
For this exercise we will choose to have the button announce its presence:
Private Sub CommandButton1_Click() Msgbox ("I have arrived!") End Sub
Activating the Command Button:
Note that on the toolbar "Control Toolbox" the "Design Mode" tool is highlighted. Click once to exit design mode, then click once on your command button. You should see your little welcome message pop up.
Customizing the Command Button:
Re-enter design mode by choosing the Design Mode tool from the Control Toolbox, left-click, then right-click on the command button and bring up the Properties box.
- Select AutoSize = TRUE.
- Choose a background colour from the palette.
- Change the caption to read "Click Me!"
- Change the font.
- Change the (text) foreground colour.
- Change the mouse pointer.
- Select a bit-map graphic from c:\windows for a picture.
- Set word-wrap to be true.
709-218-7927 CPRGreaves@gmail.com Bonavista, Sunday, December 08, 2024 9:31 AM Copyright © 1990-2024 Chris Greaves. All Rights Reserved. |
---|