Exploring Office 2007: Create Your Own Feedback Quiz in PowerPoint 2007 Using ActiveX Controls in PowerPoint to Gather Info Helen Bradley
Not all PowerPoint presentations are meant to be viewed in front of a large audience. Many presentations are designed for individual viewing at the user's leisure.
When you're creating a single user PowerPoint presentation and when you need to gather information from that user you can do it using ActiveX controls. In this article, I'll show you how to do this in PowerPoint 2007.
»
Display the Developer Tab
To start you need to display the PowerPoint Developer tab on the Ribbon. Click the Office button, choose PowerPoint Options > Popular and enable the Show Developer tab in the Ribbon checkbox and click OK. The Developer tab provides access to the ActiveX controls central to this solution.
»
Create the Form Objects
Now add a new slide to your presentation — choose one with only the title and no placeholders. Click the Developer tab, click the Label (ActiveX Control), and drag to create a Label on the slide.
Right click the Label, choose Properties, and in the properties dialog locate the Caption property and set it to read "Your Name:" (without the quote marks). The caption will appear in the label on the slide. Size the label just large enough to display its text.
You'll use a textbox for the user to type their name, so click the Text Box (ActiveX Control) on the tab and drag a textbox onto the slide. You can now add another label and textbox combination. This time set the Label's caption property to Email Address. You can continue to add more labels and textboxes for any other information that you want to retrieve from your user.
To format the Labels and Textboxes, click on each in turn and, from the Properties dialog, click in the Font area and double-click the ellipsis button to open the Font dialog to change the font of that object.
Finish the project by clicking the Command Button (ActiveX Control) and click and drag a button onto your form. Change the button's Caption property to read Submit.
»
Create the Code
You need some code to take the answers from the objects on the slide and to write them to a text file on disk. To do this, double-click the Submit button to open the Visual Basic Editor in the CommandButton1_Click event area.
Type the code below — the Sub… and End Sub statements will already be in place on the screen:
Private Sub CommandButton1_Click()
Dim myanswer As String
'Open or create file for the user information
Open ActivePresentation.Path & "\info.txt" For Append As #1
'send the name entered to the text file
myanswer = "Name: " & TextBox1.Text
Print #1, myanswer
'send the email address entered to the text file
myanswer = "Email address: " & TextBox2.Text
Print #1, myanswer
'add a blank line to the file
myanswer = ""
Print #1, myanswer
Close #1
'Tell the user that the information has been recorded
MsgBox "Your information has been recorded, thank you!"
'Clear the entries in the form
TextBox1.Text = ""
TextBox2.Text = ""
'Move to next slide
SlideShowWindows(1).View.Next
End Sub
In this example, I have included code for just the two textboxes: TextBox1 and TextBox2. If you want to add more textboxes you can add code for them following the general pattern of the code above.
The code includes a message box (MsgBox), which appears to confirm that the information has been submitted. After that the contents of the textboxes will be cleared again, reassuring the user that the information has been "sent." The presentation then moves forward to the next slide.
The lines that are prefixed with a single apostrophe are comments and are not executable code. They will help you understand what's happening at each point in the program.