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)?

You can use quiz slides to make presentations more engaging and fun. They work something like this: Each slide asks a question and displays answer choices. Quiz-takers  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.

You may think that working with VBA is too complicated, but it’s easier than you might think. This VBA code is easy to understand and, for this tip I was able to use Visual Basic to create a 10-slide quiz in less than an hour.

Step 1: Create multiple-choice slides

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

To add the multiple-choice answers, go to the Draw toolbar and choose AutoShapes> Action Buttons. (2007: Home tab> Drawing group> Shapes> Action Buttons section) Then choose the blank action button. Now click on the slide and the new button will appear. When the Action Settings dialog box appears, choose Cancel. You’ll return to this box later in the tutorial.

Resize and position the button on the slide. For consistency, size the button to allow for the longest text answer. Format the button as desired.

answer buttons

answer buttons

Right-click on the button, choose Add Text from the shortcut menu, and type the first answer. Now select the button, copy it to the Clipboard, and paste  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. You can also align and distribute the answer buttons on the slide. Select them all. Choose Draw toolbar> Align or Distribute, Align Left, then Draw toolbar> Align or Distribute> Distribute Vertically. (In PowerPoint 2007: Drawing Tools Format tab> Arrange group> Align button> Align Left, then Align button>Distrubte Vertically)

Repeat this process 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 slide’s text.

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

Step 2: Create macros

When the Q & A slides are done, you’re 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.

To open the Visual Basic Editor, choose Tools> Macro> Visual Basic Editor.

In 2007 and later, you first need to display the Developer tab if it isn’t already displayed. (By default, it is not displayed.)Choose Office button> PowerPoint Options. In PowerPoint 2007, in the Popular category, check the Show Developer Tab in the Ribbon check box. In PowerPoint 2010 and 2013, go instead to the Customize Ribbon category. On the right side of the dialog box, check the Developer check box.

Then, to open the Visual Basic Editor, choose Developer tab> Code group> Visual Basic.

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’ll create three macros.

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

Sub Wrong()

MsgBox (“Sorry, that’s not right. Please try again.”)

End Sub

In certain situations, 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 Enter. This begins a new code group. Then type the following four lines:

Sub Right()

MsgBox (“That’s right!”)


End Sub

This code is similar to the previous macro, except for the third 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,” press Enter again and type your final piece of code:

Sub RightLast()

MsgBox (“Congratulations!”)

End Sub

macro to exit to exit the slideshow

Step 3: Attach macros to buttons

To return to PowerPoint from the Visual Basic Editor, click 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 saves the new macros as well.

Go to your first question slide and select the button with the correct answer. Note: Select the entire button, not just the text on the button. You do this by clicking on the border around the edge of the button.

Right-click the button and choose Action Settings from the shortcut menu. The Action Settings dialog box appears. Choose the Mouse Click tab, and in the Action on Click section, check the Run Macro option 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. (Note: Thanks for one of the commenters below for pointing out that you may have to choose Hyperlink instead of Action Settings.)

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. 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 RightLast macro to the correct answer  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.

Be sure to save the PowerPoint file.

Step 4: The final setup

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 ESC key.

final setup

final setup

Now, go into Slide Show mode and try your quiz, making sure all wrong answers and right answers use the proper macro. If you get a message about macros, you’ll need to tell PowerPoint that you want to run the macros. This is due to PowerPoint’s security settings.

That wasn’t so difficult, was it?

This article is translated to Serbo-Croatian language by Anja Skrba at Webhostinggeeks.com.

This article is also translated into Mongolian by Chinua Dalan at MedAlertSystems.net.

If you found this useful, please use the buttons below to share it!

48 comments to Easily create a quiz in PowerPoint using Visual Basic for Applications

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>