MODULES > QUIZ > CERTIFICATE

GENERATE CERTIFICATE WITH NAME IN POWERPOINT QUIZ GAME

Many teachers and Human Resource Managers have requested for this feature where we get to generate a certificate which contains the name of the student or the employee and save the certificate as a PDF file.

This allows a proof to exist that the quiz was answered with sufficient accuracy as I have introduced an option that the Certificate should only get printed if they secure at least 50 percentage in the Quiz.

'Slide Number 2 (Slide11) - Proceed Command Button'
Private Sub CommandButton1_Click()
Set CertificateSlide = ActivePresentation.Designs(2).SlideMaster.CustomLayouts(2)
CertificateSlide.Shapes("CName").TextFrame.TextRange = TBName.Value
CertificateSlide.Shapes("CLocation").TextFrame.TextRange = TBLocation.Value
ActivePresentation.SlideShowWindow.View.Next
End Sub 
'Slide Number 10 (Slide8) - Print Certificate Command Button'
Private Sub CommandButton1_Click()
Set CertificateSlide = ActivePresentation.Designs(2).SlideMaster.CustomLayouts(2)
CertificateSlide.Shapes("CPercentages").TextFrame.TextRange = Int(SlideLayout24.Percentages.Caption)

If (SlideLayout24.Percentages.Caption) > 50 Then

'Print the certificate'

'1. Choosing the location:'
Application.FileDialog(msoFileDialogFolderPicker).Show
Dim Location As String
Location = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"

'2. Declaring the slides which are to be printed'
Set SlidesToBePrinted = ActivePresentation.PrintOptions.Ranges.Add(10, 11)

'3. Exporting it as a .pdf file'
ActivePresentation.ExportAsFixedFormat Location & Slide11.TBName.Value & " Quiz Game Certificate" & ".PDF", ppFixedFormatTypePDF, , , , , , SlidesToBePrinted, ppPrintSlideRange

'4. Return to Slide Show Mode'
ActivePresentation.Windows(1).WindowState = ppWindowMinimized 'Remove this life if you are saving it .ppsm format'
Output = MsgBox("PDF has been generated", vbInformation, "Certificate has been printed")

Else

Output = MsgBox("Your percentage is less than 50. Certificate cannot be printed", vbCritical, "Secure above 50 percentage")
End If
End Sub 

I HIGHLY SUGGEST WATCHING THE VIDEO IN ITS ENTIRETY. IT EXPOSES YOU TO VARIOUS ASPECTS OF VISUAL BASIC CODING FOR POWERPOINT

Saving it in .PPSM format

We can save the PowerPoint Interactive Quiz Game which can generate a certificate in .PPSM format so that it opens directly in Slide Show Mode. While doing this, remember to delete the following line of code from the PrintCertificate Sub-Routine which is inside Slide10 CommandButton1

ActivePresentation.Windows(1).WindowState = ppWindowMinimized 'Remove this life if you are saving it .ppsm format' 

Removing decimals from the Percentages in VBA

Int(66.6666666) 

The above code will give you the output – 16. It becomes a pain when the certificate prints 16.66666% so we use the Int function to remove all the decimals from the percentage of the student in the PowerPoint Quiz Game.

Slide Name vs Slide Number in PowerPoint VBA

This is a personal pet peeve of mine and it is very confusing for beginners of PPT VBA scripting. 

We need to understand that the slide number 3 (say) will not always be named Slide3. The slides are named chronologically on the basis of its creation. If you have 100 slides, and you decide to insert a new slide in your powerpoint presentation, the latest slide will be named Slide101 and you can insert Slide101 between the 5th and 6th slide (say) and it will still be named Slide101 even though it is slide number 6.

So, when we clear the values of the TBName and TBLocation ActiveX Textboxes, we need to mention where those 2 TextBoxes are present:

Slide11.TBName.Value = ""
Slide11.TBLocation.Value = ""