Share via

PowerPoint Quiz - VBA to print result

Anonymous
2016-10-16T13:12:33+00:00

I have some PowerPoint quizes that the following VBA code is for but I want to be able to print the result however when it prints the slide the msgBox is not printed.

Anyone got any ideas?

Public NumberCorrect As Integer

Dim userName As String

'Public variables retain their value so they can be added to each time a macro is run.

Sub Initialise()

'Sets the score to zero so it’s not added to the previous user’s total, and goes to the first question.

NumberCorrect = 0

ActivePresentation.SlideShowWindow.View.Next

End Sub

Sub Correct()

'Adds one to the total correct and moves to the next slide

NumberCorrect = NumberCorrect + 1

End Sub

Sub Wrong()

'Takes away one to the total correct and moves to the next slide

NumberCorrect = NumberCorrect - 1

End Sub

Sub Display()

'Shows the result in a pop-up message box with some explanatory text

percent = ((NumberCorrect * 4.347826) * 1)

percent = Round(percent, 0)

MsgBox (userName & " got " & percent & " % correct")

PrintLastSlide

End Sub

Sub YourName()

    Dim done As Boolean

        done = False

        ActivePresentation.SlideShowWindow.View.Next

    While Not done

        userName = InputBox(prompt:="Type your name", _

            Title:="Input Name")

        If userName = "" Then

            done = False

        Else

            done = True

        End If

    Wend

ActivePresentation.SlideShowWindow.View.Next

End Sub

     Sub PrintLastSlide()

ActivePresentation.PrintOptions.OutputType = ppPrintOutputSlides

ActivePresentation.PrintOut From:=20, To:=20

ActivePresentation.SlideShowWindow.View.Exit

  End Sub

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

13 answers

Sort by: Most helpful
  1. Steve Rindsberg 99,161 Reputation points MVP Volunteer Moderator
    2016-10-17T02:45:41+00:00

    After this:

    .TextFrame.TextRange.Text = (userName & " got " & percent & " % correct")

    add this:

    .Name = "Score"

    Then after this:

    ActivePresentation.PrintOut From:=21, To:=21

    Add:

    ActivePresentation.Slides(21).Shapes("Score").Delete

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-10-16T20:55:26+00:00

    Things are getting very close now toa  working VBA interactive quiz that  I want.

    The problem now is when I initialise back to the start for the next peson, the text box on the last slide is over written by the next person's score I need to delete/reset this text box on start,

    Public NumberCorrect As Integer

    Dim userName As String

    'Public variables retain their value so they can be added to each time a macro is run.

    Sub Initialise()

    'Sets the score to zero so it’s not added to the previous user’s total, and goes to the first question.

    NumberCorrect = 0

    With SlideShowWindows(1).View

        .GotoSlide 1

    End With

    End Sub

    Sub Correct()

    'Adds one to the total correct and moves to the next slide

    NumberCorrect = NumberCorrect + 1

    End Sub

    Sub Wrong()

    'Takes away one to the total correct and moves to the next slide

    NumberCorrect = NumberCorrect - 1

    End Sub

    Sub Display()

    'Shows the result in a pop-up message box with some explanatory text

    percent = ((NumberCorrect * 4.347826) * 1)

    percent = Round(percent, 0)

    MsgBox (userName & " got " & percent & " % correct")

    ActivePresentation.SlideShowWindow.View.Next

    End Sub

    Sub YourName()

        Dim done As Boolean

            done = False

            ActivePresentation.SlideShowWindow.View.Next

        While Not done

            userName = InputBox(prompt:="Type your name", _

                Title:="Input Name")

            If userName = "" Then

                done = False

            Else

                done = True

            End If

        Wend

    ActivePresentation.SlideShowWindow.View.Next

    End Sub

          Sub PutTextOnSlideExample()

    ' This will add text to slide 1

    ' Change to whatever slide you need the text on

    ' Change the Left, Top, Width, Height (in that order) as needed

     percent = ((NumberCorrect * 4.347826) * 1)

     percent = Round(percent, 0)

     With ActivePresentation.Slides(21)

     With .Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 500, 100)

          .TextFrame.TextRange.Text = (userName & " got " & percent & " % correct")

     End With

     End With

    PrintLastSlide

    End Sub

        Sub PrintLastSlide()

    ActivePresentation.PrintOptions.OutputType = ppPrintOutputSlides

    ActivePresentation.PrintOut From:=21, To:=21

    ActivePresentation.SlideShowWindow.View.Exit

      End Sub

    Was this answer helpful?

    0 comments No comments
  3. Steve Rindsberg 99,161 Reputation points MVP Volunteer Moderator
    2016-10-16T17:27:42+00:00

    Here's something to start with; modify at will:

    Sub PutTextOnSlideExample()

    ' This will add text to slide 1

    ' Change to whatever slide you need the text on

    ' Change the Left, Top, Width, Height (in that order) as needed

    With ActivePresentation.Slides(1)

    With .Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 500, 100)

    .TextFrame.TextRange.Text = "Here is your new text"

    End With

    End With

    End Sub

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-10-16T15:56:13+00:00

    Thanks for the heads up about msgBox.

    Got any examples of VBA code to to this.  I am not too good at writing VBA but have modified bits of code.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2016-10-16T13:31:16+00:00

    MsgBoxes will not print. You need to modify your code to add the results to a slide not display as a message box.

    Was this answer helpful?

    0 comments No comments