ID: Q168409
The information in this article applies to:
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:
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/refguide/default.asp
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.
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.
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.
2. 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.
3. 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:
ARTICLE-ID: Q176476
TITLE : OFF: Office Assistant Not Answering Visual Basic Questions
Code that changes the properties of an ActiveX Control is considered a run- time change.
To add code to the control, use these steps:
1. 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.
2. In the Object drop-down list, click TextBox1.
3. 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:
1. Start the slide show.
2. On the Slide Show menu, click View Show.
3. Double-click the Text Box control.
The following message appears:
A double click event
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.
1. Create a blank presentation.
a. On the File menu, click New, and then click the General tab.
b. Click the Blank Presentation icon and click OK.
c. Click the Title Only AutoLayout and click OK.
2. Type the following text in the Title placeholder:
This is a test.
3. Insert a Command Button control on the slide.
a. On the View menu, point to Toolbars, and then click Control
Toolbox.
b. Click Command Button on the Control Toolbox toolbar, and draw
the control on the slide.
4. 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.
5. 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.
6. Double-click the Command Button control.
The Visual Basic Editor appears.
7. 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
8. To run the code, start the slide show ,and then do the following:
a. On the Slide Show menu, click View Show.
b. 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.
For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q163435
TITLE : 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
Hardware : x86
Issue type : kbhowto
Last Reviewed: May 17, 1999