About Chemistry, Environment, Waste Management and Green Life Inspirations

21 June 2010

Easily create a quiz in PowerPoint using Visual Basic for Applications

Easily create a quiz in PowerPoint using Visual Basic for Applications Did you know it's possible to create your own quiz slides in Microsoft PowerPoint using its macro functions and doing a little programming in Visual Basic for Applications (VBA)?

Quiz slides can be used to make presentations more engaging and fun. They work something like this: Each slide asks a question and displays answer choices. Quiz-takers (or audience members) then click on the answer they think is correct. If they answer correctly, a "congratulations" message appears and they automatically move on to the next slide. If they choose a wrong answer, they receive a "try again" message. The slideshow will not advance until they select the correct answer.

Some presenters may believe working with VBA and macros is too complicated, but it's easier than you might think. The VBA code is easy to understand and, for this article, I was able to use Visual Basic to create a 10-slide quiz in less than an hour.

Create multiple-choice slides

The first step is to create the question slides. Within PowerPoint, start a new slide using the Title Only slide layout. Type the first question in the title-text placeholder.

To add the multiple-choice answers, go to the Draw toolbar and choose AUTOSHAPES » ACTION BUTTONS. Then choose the first action button, which is blank (aka Action Button: Custom). Now click on the slide and the new button will appear. Tip: If the Action Settings dialog box appears, choose Cancel. You will return to this box later in the tutorial.

Resize and position the button on the slide. For consistency, you should size the button to allow for the longest text answer.

Right-click on the button, choose Add Text from the subsequent menu, and type the first answer. Now select the button, right-click again, and choose Copy from the Edit menu. paste (CTRL+V) additional copies of the button graphic for the remaining answers you'll need on the slide.

When all the buttons are in place, select each individually and edit its text and color (right-click, then select the FORMAT AUTOSHAPE » COLORS AND LINES tab). You can also align the answer buttons on the slide using the Draw toolbar (DRAW » ALIGN OR DISTRIBUTE » ALIGN LEFT, then DRAW » ALIGN OR DISTRIBUTE » DISTRIBUTE VERTICALLY).

Repeat Step One to create each additional question slide. Tip: Within the Slide Sorter view, you can COPY (CTRL+C) the first question slide and PASTE it as many times as needed to quickly create the remaining question slides. Then return to Normal view to edit each slides' text.

On your final quiz slide, create an action button with the word End, and place it on the slide.

Create macros

When the Q & A slides are done, you are ready to create the macros using PowerPoint's Visual Basic Editor. Before you begin, make sure that only the presentation you are currently working on is open.

From the TOOLS menu, choose MACRO » VISUAL BASIC EDITOR. The editor opens in a new window. The right side of the window will be gray. From the insert menu choose module and you'll see a blank white area where you can type a macro. We will create three macros.

We'll start with the code for the wrong answer. In the big blank space on the right, type the following three lines:

Sub Wrong()
MsgBox ("Sorry, that's not right. Please try again.")
End Sub

If you make a mistake, the editor will warn you, but the message may not be clear to you. Most often the mistake is a result of mistyping the code. You may have left out one of the quotation marks or the closing parenthesis at the end of a line. Double-check your typing and make adjustments until the Editor shows no warnings.

Next is the code for the right answer. At the end of the line reading "End Sub," press the enter key on your keyboard. This begins a new code group. Type the following four lines below your first code group:

Sub Right()
MsgBox ("That's right!")
End Sub

This code is similar to the previous macro, except for its "SlideShowWindows" line, which advances the quiz-taker to the next slide.

On the final slide, you don't want the slideshow to advance to the next slide because that starts the presentation all over again. Instead, you want viewers to use a button that exits the slideshow. So after the previous "End Sub," hit the ENTER key again and type your final piece of code:

Sub RightLast()
MsgBox ("Congratulations!")
End Sub

Attach macros to buttons

To return to PowerPoint from the Visual Basic Editor, click on the View Microsoft PowerPoint icon (upper left-hand corner, under the FILE menu link). Leave the Visual Basic Editor open in the background. In PowerPoint, save the presentation, as this will save the new macros as well.

Go to your first question slide and select the button with the correct answer. Tip: Select the entire button, not just the text on the button.

Right-click on the button and choose Action Settings from the subsequent menu. The Action Settings dialog box will appear. Choose the Mouse Click tab, and from the "Action on click" area, check the "Run macro" radio button and select your new "Right" macro from the drop-down list. (Notice that all the macros on this list are named for the three pieces of code you created in the Visual Basic Editor.) Click OK.

Now select each of the wrong answers and follow the same procedure, except select the "Wrong" macro from the drop-down list.

Before going on to the other slides to assign the proper macros, try out the buttons on the first slide. Go into Slide Show view (SLIDE SHOW » VIEW SHOW). Click on a wrong answer. A text-message box should pop up indicating you have chosen the wrong answer. Click OK to close the box. Check the other wrong answers on the slide to make sure they also work. Finally, select the correct answer. This time, the text-message box should indicate you have chosen the right answer. Click OK and the slideshow will automatically advance to the next slide.

With the first slide working properly, edit the rest of the presentation, attaching the appropriate macros to the buttons. On the last slide, assign the correct answer to the "RightLast" macro so that quiz-takers stay on the last slide.

Remember the "End" button you created on this final slide? Right-click on that button and choose Action Settings. In the Action Settings dialog box, choose the "Hyperlink to" option and choose End Show from the drop-down list. Click OK. Quiz-takers can use this button when they're finished answering all the questions.

Once you have assigned macros to all of the action buttons, save the PowerPoint file.

The final setup

Finally, to prevent the quiz-takers from clicking through without answering all the questions, choose SLIDE SHOW » SET UP SHOW. In the Set Up Show dialog box choose the "Browsed at a kiosk (full screen)" option under the "Show type" area. Click OK. With this setting, the only way someone can get out of the presentation is to use the ESCAPE key.

Now, go into Slide Show mode and try your quiz, making sure all wrong answers and right answers use the proper macro. That wasn't so difficult, was it?

Being able to set up a VBA quiz opens up many other presentation possibilities. If you're interested in pursuing the use of macros in PowerPoint, I highly recommend the "Making PowerPoint Interactive" area of the State of Tasmania (Australia) Department of Education's Web site at www.education.tas.gov.au/itproject/ppt_vba. The explanations are clear and simple, and you'll be surprised what you can accomplish in a short time. For advanced options, try David Marcovitz' site at www.loyola.edu/education/powerfulpowerpoint. It has lots of quiz examples you can use by simply substituting questions and answers. You can also buy Marcovitz' book from the site, Powerful PowerPoint for Educators: Using Visual Basic for Application to Make PowerPoint Interactive.

Read more: http://www.ellenfinkelstein.com/powerpoint_tip_create_quiz_with_vba.html#ixzz0rYQoWe5w

No comments:

Post a Comment