PPT97: How To Manipulate ActiveX Controls Through VBA Macros
ID: Q168409
|
The information in this article applies to:
-
Microsoft PowerPoint 97 For Windows
SUMMARY
This article provides basic information about how to add code to an ActiveX
control which you can insert on a form or on a slide. This article is
organized into the following four sections:
- Adding an ActiveX Control to a Slide or a Form
- Viewing the Properties of an ActiveX Control
- Writing an Event Handler for the ActiveX Control
- Using an Event Handler to Control Another Control
MORE INFORMATION
Microsoft provides programming examples for illustration only, without
warranty either expressed or implied, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft Support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to
provide added functionality or construct procedures to meet your specific
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp Adding an ActiveX Control to a Slide or a Form
Use the following steps to add a Text Box control to a slide.
NOTE: You can also use these steps to add a control to a form.
- Go to the slide where you want to insert the control.
- On the View menu, point to Toolbars, and then click Control
Toolbox.
- Click the Text Box button on the Control Toolbox toolbar, and draw
the control on your slide.
To add a third-party control, click the More Controls button
on the Control Toolbox toolbar, click the control you want to use,
and then draw the control on your slide.
The Text Box ActiveX control now appears on your slide.
NOTE: If a third-party control is on your computer but it does not appear
in the list of controls, it may not be registered. To register the control,
click Register Custom Control at the bottom of the list of controls (click
the More Controls button on the Control Toolbox toolbar) and then locate
the third-party control.
Viewing the Properties of an ActiveX Control
The behavior of an ActiveX control is modified by manipulating the
properties for the control. You can edit the control properties before
run-time (before your slide show runs) or during run-time (while the slide
show runs).
NOTE: You cannot edit some control properties during run-time.
Use the following steps to view the property sheet for a control. Any
changes you make to the property sheet are considered to be before
run-time changes.
- Right-click the Text Box control, and then click Properties.
NOTE: In PowerPoint, the only controls that have a property
sheet are those from MSForms: Check Box, Combo Box, Command Button,
Frame, Image, Label, List Box, MultiPage, Option Button, Scroll
Bar, Spin Button, Tab Strip, Text Box, and Toggle Button.
- In the Properties window, click the Alphabetic tab, and locate the
property you want to change. For example, find the property called
Text. In the value box, type the text you want to use for the Text
property. For example, type your name. You will see something like
this in the Property window:
Text <Your Name>
and your name appears in the Text Box control on the slide.
You can also change the properties using the Categorized tab. This
view organizes the properties into distinct categories, such as
appearance, behavior, font and so on.
- Change any other properties you want and then look at the control
to see how the property affects the control.
NOTE: To obtain help on a property, click the property and press
the F1 key. If Visual Basic Help is not installed on your computer,
please see the following article in the Microsoft Knowledge Base:
Q176476
OFF: Office Assistant Not Answering Visual Basic Questions
Writing an Event Handler for the ActiveX Control
Code that changes the properties of an ActiveX Control is considered a run-
time change.
To add code to the control, use these steps:
- Right-click the control, and then click View Code.
The Code window where you can add code for your control appears
on the right side of the Visual Basic Editor.
- In the Object drop-down list, click TextBox1.
- In the Procedure drop-down list, click DblClick.
A subroutine called TextBox1_DblClick appears in the Code window.
Type the following code in the subroutine:
MsgBox "A double click event"
The complete TextBox1_DblClick procedure should look similar to
this:
Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "A double click event"
End Sub
NOTE: The line that begins "Sub TextBox1..." actually begins with the
word "Private" in the Code window, but it was removed from this example
to shorten the line length.
To run the code, use these steps:
- Start the slide show.
- On the Slide Show menu, click View Show.
- Double-click the Text Box control.
The following message appears:
A double click event
Using an Event Handler to Control Another Control
In some cases you may want to create a control that modifies the behavior
of another control. One example of this type of control is the New Slide
dialog box (on the Insert menu, click New Slide). In the New Slide dialog
box, when you select an AutoLayout, the text in the lower right corner of
the dialog box changes to reflect the selected AutoLayout. Each time you
choose a different AutoLayout, the text string updates to reflect the name
of the currently selected AutoLayout.
The following code example uses a command button to retrieve the title of a
slide and displays that title in a text box.
- Create a blank presentation.
- On the File menu, click New, and then click the General tab.
- Click the Blank Presentation icon and click OK.
- Click the Title Only AutoLayout and click OK.
- Type the following text in the Title placeholder:
This is a test.
- Insert a Command Button control on the slide.
- On the View menu, point to Toolbars, and then click Control
Toolbox.
- Click Command Button on the Control Toolbox toolbar, and draw
the control on the slide.
- Insert a Text Box control on the slide. Click the Text Box
button on the Control Toolbox toolbar and draw the control on the
slide, making sure it is large enough to hold the title.
- Right-click the Text Box control, and then click Properties.
At the top of the Properties window, you will see a list box that
contains the following:
TextBox1 TextBox
The first item, TextBox1, is the name of the control; the second
item, TextBox, is the type of control.
NOTE: If you want to change the name of a control, do this in the
Property window. The property called, (Name), holds the name of the
control.
- Double-click the Command Button control.
The Visual Basic Editor appears.
- Type the following code in the Code window:
With Slide1
' Check if any text is in the Text Box control.
If TextBox1.Text = "" Then
' If no text in the Text Box control, add the text
' from the Title placeholder to the control.
TextBox1.Text = .Shapes.Title.TextFrame.TextRange
Else
' If text is already in the control, delete the text.
TextBox1.Text = ""
End If
End With
The completed code for the click event handler looks like this:
Private Sub CommandButton1_Click()
With Slide1
' Check if any text is in the Text Box control.
If TextBox1.Text = "" Then
' If no text in the Text Box control, add the text
' from the title placeholder to the control.
TextBox1.Text = .Shapes.Title.TextFrame.TextRange
Else
' If text already in the control, delete the text.
TextBox1.Text = ""
End If
End With
End Sub
- To run the code, start the slide show ,and then do the following:
- On the Slide Show menu, click View Show.
- Click the Command Button control. Remember, the event handler
is for CommandButton1_Click. This is a handler for a single
click event.
The first time you click the button the text from the title is
copied into the Text Box control. The second time you click the
button, the text in the Text Box control is deleted.
REFERENCES
For more information about getting help with Visual Basic for Applications,
please see the following article in the Microsoft Knowledge Base:
Q163435
VBA: Programming Resources for Visual Basic for
Applications
Additional query words:
8.00 ppt8 97 ppt97 vba vbe visual basic applications
Keywords : kbcode kbmacro kbprg kbdta kbdtacode kbpptvba
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto
|