VBA & Macro Problems

Create a PowerPoint Quiz Game with VBA and Command Buttons

Adam DavisAdam Davis Nov 14, 2026 868 views

Question details

The user wants to create an interactive PowerPoint quiz with answer buttons, animations, navigation, and scoring across slides.

Create a PowerPoint Quiz Game with VBA
Product
Microsoft PowerPoint
Device & OS
not provided
Scenario
A quiz uses buttons and animations on multiple slides to respond to player answers.
Observed behavior
The desired quiz tracks answers and moves between slides, using VBA for logic that spans slides.
Before you start

Create a presentation with a start slide, two question slides, and a results slide in that order. Make sure your PowerPoint version supports VBA macros and that you can enable macros for a trusted presentation.

Solution 1Recommended

Use VBA macros to control quiz answers and scoring

Use this four-slide example to connect answer buttons to quiz logic and display a score at the end.

PowerPoint animation triggers generally operate on objects on the same slide. VBA can maintain a score and navigate between slides, while you can still add slide-specific animations separately.

This example has one correct answer per question and a maximum score of two. It assumes players answer each question once without navigating backward.

1
Save a macro-enabled presentation

In PowerPoint, select File > Save As and choose PowerPoint Macro-Enabled Presentation (.pptm). Arrange the start slide as slide 1, question slides as slides 2 and 3, and the results slide as slide 4.

2
Add the quiz code

Open Developer > Visual Basic, choose Insert > Module, and paste the following code into the standard module: Dim quizScore As Integer Public Sub StartQuiz() quizScore = 0 ActivePresentation.SlideShowWindow.View.GotoSlide 2 End Sub Public Sub AnswerCorrect() quizScore = quizScore + 1 NextQuestion End Sub Public Sub AnswerWrong() NextQuestion End Sub Private Sub NextQuestion() Dim currentSlide As Long currentSlide = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex If currentSlide < 3 Then ActivePresentation.SlideShowWindow.View.GotoSlide currentSlide + 1 Else ActivePresentation.SlideShowWindow.View.GotoSlide 4 MsgBox "Your score: " & quizScore & " out of 2" End If End Sub

3
Assign macros to buttons

Add shapes for the start and answer buttons using Insert > Shapes. Select each shape, choose Insert > Action, select Run macro, and assign StartQuiz to the start button, AnswerCorrect to each correct answer, and AnswerWrong to each incorrect answer.

4
Test the quiz

Save the presentation, enable macros if prompted for this trusted file, and start Slide Show > From Beginning. Click the start button and answer both questions to check navigation and the final score.

5
Add optional animations

Select an object on a question slide and use Animations > Add Animation and Trigger to set up slide-specific visual effects. Keep the VBA macros assigned to the answer buttons for scoring and navigation.

Use VBA macros to control quiz answers and scoring
Slide order matters: The code uses slide numbers 2, 3, and 4. If you add or reorder slides, update the numbers in the module. More questions or protections against repeat scoring require additional logic.
Free Microsoft Office alternative

Create and edit quiz slides in WPS Presentation

WPS Office is a free, lightweight alternative with a familiar interface for creating and editing presentations. Open PowerPoint files to migrate slide content, but test VBA-dependent quiz behavior separately because WPS does not necessarily support the same macros.

Create quiz slides with shapes, text, and animationsCompatible with Microsoft PowerPoint PPT and PPTX presentation formatsFamiliar presentation-editing interfaceFree and lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

Why use VBA instead of animation triggers for the quiz?

Animation triggers generally control objects on the same slide. VBA can keep a score and use SlideShowWindow.View.GotoSlide to navigate between slides.

How do I make an answer button run a macro?

Select the button shape, choose Insert > Action, select Run macro, and choose the appropriate public macro. Test it in Slide Show mode.

Why does the quiz need a PPTM file?

A PowerPoint Macro-Enabled Presentation preserves VBA code. Use File > Save As and select the PPTM format, then enable macros only when you trust the file.

Can I add more than two questions?

Yes. Add question slides and update the slide numbers and score total in the VBA module. You may also need additional logic to prevent players from scoring twice on the same question.