Microsoft KB Archive/222703

= PPT2000: How to Manipulate ActiveX Controls Through VBA Macros =

Article ID: 222703

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft PowerPoint 2000 Standard Edition

-



This article was previously published under Q222703





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. NOTE: The following macro examples work only in PowerPoint. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

Adding an ActiveX Control to a Slide or a Form
To add a Text Box control to a slide, following these steps:

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.

Any changes you make to the property sheet are considered to be before run-time changes. To view the property sheet for a control, follow these steps:
 * 1) 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 F1.

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, follow 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 list, click TextBox1.  In the Procedure 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 the following: 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, follow 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. Make 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 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 the following: 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 follow these steps: <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.</li></ol>

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>

<div class="references_section">