Microsoft KB Archive/168409

= PPT97: How To Manipulate ActiveX Controls Through VBA Macros =

Article ID: 168409

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft PowerPoint 97 Standard Edition

-



This article was previously published under Q168409



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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

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.


 * 1) Go to the slide where you want to insert the control.
 * 2) On the View menu, point to Toolbars, and then click Control Toolbox.
 * 3) 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 

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:

176476 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.</li>  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. </li></ol>

To run the code, use these steps:

 Start the slide show.</li> On the Slide Show menu, click View Show.</li> Double-click the Text Box control.

The following message appears:

A double click event

</li></ol>

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.</li> Click the Blank Presentation icon and click OK.</li> Click the Title Only AutoLayout and click OK.</li></ol> </li> Type the following text in the Title placeholder:

This is a test.

</li> Insert a Command Button control on the slide.

 On the View menu, point to Toolbars, and then click Control Toolbox.</li> Click Command Button on the Control Toolbox toolbar, and draw the control on the slide.</li></ol> </li> <li>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.</li> <li>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.</li> <li>Double-click the Command Button control.

The Visual Basic Editor appears.</li> <li> 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 </li> <li>To run the code, start the slide show ,and then do the following:

<ol style="list-style-type: lower-alpha;"> <li>On the Slide Show menu, click View Show.</li> <li>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.</li></ol> </li></ol>

<div class="references_section">