Project 5: Creating a VBA Form in a Presentation


Skills and Tools: ActiveX controls and Visual Basic for Applications (VBA) form

An ActiveX control is a software component that adds functionality to an existing program. An ActiveX control supports a customizable, programmatic interface using VBA, which you can use to create your own functionality, such as a form. Excel includes several pre-built ActiveX controlsincluding a label, text box, command button, and check boxto help you create a user interface.

The Project

In this project, you'll learn how to create a form using VBA that allows users to apply a template to the active presentation. You'll also learn how to insert a picture from a selected folder, and show the active presentation in Slide Show view.

The Process

Open PowerPoint 2007, open VBA_Form_start.potm, and then save it as VBA_Form_pres.pptm (macro-enabled presentation).

  • Create a form.

Click the Developer tab.

Click the Visual Basic button.

Click the Insert menu, and then click UserForm.

A new form, UserForm1, opens and the Toolbox appears, displaying controls.

Click the Label button in the Toolbox.

Position the mouse pointer in the upper-left corner of the form, and then click the mouse button.

A label appears selected on the form with the default caption, Label1.

Click the ComboBox button in the Toolbox.

Position the mouse pointer below the Label1 control, and then click the mouse button.

The ComboBox button appears selected on the form.

Repeat steps 5 through 8 to add Label2 control, and second ComboBox control to the form, and then repeat steps 5 through 6 to add Label3 control to the form.

Click the CommandButton button in the Toolbox.

Position the mouse pointer below the second ComboBox, and then click the mouse.

The CommandButton1 button appears selected on the form.

Repeat steps 10 through 11 to add CommandButton2 and CommandButton3 to the form.

Resize the form and any of the controls to match the illustration to the right.

  • Set control properties.

Click the Label1 control on the form.

Click the View menu, and then click Properties Window, if necessary, to display the Properties window.

In the Properties window, click Caption on the Alphabetic tab.

Double-click the Label1 caption, type Select a template, and then press Enter.

Change the caption of Label2 to Select a picture, change the caption of Label3 to Select a folder, change the caption of CommandButton1 to Apply, change the caption of CommandButton2 to Show, and change the caption of CommandButton3 to Browse.

Resize the width of the two ComboBoxes to stretch across the form. The height remains the same.

  • Add VBA functionality to the form.

Click the Insert UserForm button arrow on the Standard toolbar, and then click Module.

A new module, Module1, opens.

Type the VBA code that appears in the following illustration:

Select UserForm1 in the Project Window, and then click the View Code button.

Type the initialize form procedure VBA code that appears in the following illustration:

Click the Object box arrow at the top of the Code Window, and then click CommandButton1.

In the Procedure box, type the VBA code that appears in the following illustration:

Repeat steps 5 through 6 to add VBA code for CommandButton2 and CommandButton3 to the form that appears in the following illustration:

Click the Object box arrow at the top of the Code Window, and then click (General).

Type Dim TemplateName As String, press Enter, type Dim MyPath As Variant, and then press Enter.

Compare your screen to the following illustration:

Click the Save button on the Standard toolbar.

Click the Close button on the Visual Basic Editor window to return to PowerPoint.

Click the Save button on the Quick Access Toolbar.

  • Add a button on the Quick Access Toolbar to run the form.

Click the the Customize Quick Access Toolbar list arrow, and then click Customize Quick Access Toolbar.

Click the Choose command from list arrow, and then click Macros.

Click the Customize Quick Access Toolbar list arrow, and then click For all documents (default).

Click the VBA form macro (left column).

Click Add.

Click the Move Up and Move Down arrow buttons to arrange the commands in the order you want them to appear.

Click Modify.

In the Display name box, type CompanyPres.

Click an icon from the symbol list.

Click OK.

Click OK.

Click the Save button on the Quick Access Toolbar.

Click the CompanyPres button on the Quick Access Toolbar, and then test out the form.

When you're done, click the Close button on the form.

The Results

Finish: Compare your completed project file with the presentation VBA_Form_results.pptx.



Microsoft Office PowerPoint 2007 On Demand
Microsoft Office PowerPoint 2007 On Demand
ISBN: 0789736438
EAN: 2147483647
Year: 2006
Pages: 348

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net