PDA

View Full Version : [SOLVED:] vba quiz not advancing or writing slide



dareeldill
09-27-2016, 10:23 PM
Hello VBA Gods, I come to kneel at your alter and pray for your guidance once more.

Again, I am using Powerpoint 2010, and I have gotten some great help with the below pasted code and it worked wonderfully on my first presentation. However on my second presentation the code doesn't work. Both presentations are basically the same format but with a different subject matter. I can't for the life of me figure out why its not working.

Basically it is a quiz and on the last page is a "RESULTS" Button. The button runs the Macro "PrintablePage" which ultimately should create a next slide and display all the results from the previous questions and then advance to that slide.

However when I run my slide show, even though all of my other macros up to this point performed as desired, this "RESULTS" button is causing me headaches. When I press the button nothing happens. It does not advance at all. When I press ESC to edit my slide, I notice it has created a slide but with no information written on it, just a blank slide.

As I've stated this code is copied and pasted directly from another presentation that I made that is working perfectly.

Any suggestions?



Sub PrintablePage()
Dim printableSlide As Slide
Dim homeButton As Shape
Dim printButton As Shape

Set printableSlide = _
ActivePresentation.Slides.Add(Index:=printableSlideNum, _
Layout:=ppLayoutText)
printableSlide.Shapes(1).TextFrame.TextRange.Text = _
"Results for " & userName
printableSlide.Shapes(2).TextFrame.TextRange.Text = _
"Your Answers" & Chr$(13) & _
"QUESTION 1: Correct Answer is C. Your answer is " & answer01 & Chr$(9) & "QUESTION 2: Correct Answer is B. Your answer is " & answer02 & Chr$(9) & Chr$(9) & "QUESTION 3: Correct Answer is B. Your answer is " & answer03 & Chr$(13) & _
"QUESTION 4: Correct Answer is D. Your answer is " & answer04 & Chr$(9) & "QUESTION 5: Correct Answer is B. Your answer is " & answer05 & Chr$(9) & Chr$(9) & "QUESTION 6: Correct Answer is D. Your answer is " & answer06 & Chr$(13) & _
"QUESTION 7: Correct Answer is A. Your answer is " & answer07 & Chr$(9) & "QUESTION 8: Correct Answer is B. Your answer is " & answer08 & Chr$(9) & Chr$(9) & "QUESTION 9: Correct Answer is C. Your answer is " & answer09 & Chr$(13) & _
"QUESTION 10: Correct Answer is D. Your answer is " & answer10 & Chr$(9) & "QUESTION 11: Correct Answer is C. Your answer is " & answer11 & Chr$(9) & Chr$(9) & "QUESTION 12: Correct Answer is A. Your answer is " & answer12 & Chr$(13) & _
"QUESTION 13: Correct Answer is B. Your answer is " & answer13 & Chr$(9) & "QUESTION 14: Correct Answer is A. Your answer is " & answer14 & Chr$(9) & Chr$(9) & "QUESTION 15: Correct Answer is D. Your answer is " & answer15 & Chr$(13) & _
"QUESTION 16: Correct Answer is B. Your answer is " & answer16 & Chr$(9) & "QUESTION 17: Correct Answer is D. Your answer is " & answer17 & Chr$(9) & Chr$(9) & "QUESTION 18: Correct Answer is B. Your answer is " & answer18 & Chr$(13) & _
"QUESTION 19: Correct Answer is B. Your answer is " & answer19 & Chr$(9) & "QUESTION 20: Correct Answer is C. Your answer is " & answer20 & Chr$(9) & Chr$(9) & "QUESTION 21: Correct Answer is D. Your answer is " & answer21 & Chr$(13) & _
"QUESTION 22: Correct Answer is A. Your answer is " & answer22 & Chr$(9) & "QUESTION 23: Correct Answer is C. Your answer is " & answer23 & Chr$(9) & Chr$(9) & "QUESTION 24: Correct Answer is C. Your answer is " & answer24 & Chr$(13) & _
"QUESTION 25: Correct Answer is C. Your answer is " & answer25 & Chr$(9) & "QUESTION 26: Correct Answer is C. Your answer is " & answer26 & Chr$(9) & Chr$(9) & "QUESTION 27: Correct Answer is A. Your answer is " & answer27 & Chr$(13) & _
"QUESTION 28: Correct Answer is G. Your answer is " & answer28 & Chr$(9) & "QUESTION 29: Correct Answer is D. Your answer is " & answer29 & Chr$(9) & Chr$(9) & "QUESTION 30: Correct Answer is D. Your answer is " & answer30 & Chr$(13) & _
Chr(13) & Chr(13) & "You got " & numCorrect & " out of " & _
numCorrect + numIncorrect & "." & Chr$(13) & Chr$(13) & _
"Press the Print Results button to print your answers. Press Escape to close test, if prompted DO NOT SAVE."
printableSlide.Shapes(2).TextFrame.TextRange.Font.Size = 10



Set homeButton = _
ActivePresentation.Slides(printableSlideNum).Shapes.AddShape _
(msoShapeActionButtonCustom, 0, 0, 150, 50)
homeButton.TextFrame.TextRange.Text = "Start Again"
homeButton.ActionSettings(ppMouseClick).Action = ppActionRunMacro
homeButton.ActionSettings(ppMouseClick).Run = "StartAgain"
Set printButton = _
ActivePresentation.Slides(printableSlideNum).Shapes.AddShape _
(msoShapeActionButtonCustom, 200, 0, 150, 50)
printButton.TextFrame.TextRange.Text = "Print Results"
printButton.ActionSettings(ppMouseClick).Action = ppActionRunMacro
printButton.ActionSettings(ppMouseClick).Run = "PrintResults"
ActivePresentation.SlideShowWindow.View.Next
ActivePresentation.Saved = True
End Sub


Sub PrintResults()
ActivePresentation.PrintOptions.OutputType = ppPrintOutputSlides
ActivePresentation.PrintOut From:=printableSlideNum, _
To:=printableSlideNum
End Sub


Sub StartAgain()
ActivePresentation.SlideShowWindow.View.GotoSlide 1
ActivePresentation.Slides(printableSlideNum).Delete
ActivePresentation.Saved = True
End Sub

Paul_Hossler
09-28-2016, 06:02 AM
It would help if you attached a small presentation that demos the problem

John Wilson
09-28-2016, 08:11 AM
It would help to see the presentation but my guess is this line

ActivePresentation.SlideShowWindow.View.Next

Should be

ActivePresentation.SlideShowWindow.View.GotoSlide printableSlideNum

dareeldill
09-28-2016, 09:04 AM
John, that didn't seem to work.

17205

I hope that attached the file of the presentation. I had to delete the text in the file I'm sorry due to the presentation containing protected content.

dareeldill
09-28-2016, 01:56 PM
To assist anyone trying to help me find out why the last button doesn't work, I attaching another version. Its the same thing, but this time the correct answers are labeled as "CORRECT" just to further assist anyone. I look forward to your help and assistance.

17210

John Wilson
09-28-2016, 11:38 PM
i MISSED OUT A VITAL SPACE

ActivePresentation.SlideShowWindow.View.GotoSlide printableSlideNum

I also removed the OnSlideShowPageChange code because the flash content is not embedded and gave an error (probably works on your pC but not others)

It then worked for me

17216

dareeldill
09-29-2016, 03:42 AM
John, as always, you are a constant source of support and I greatly appreciate your help. I have no clue what was wrong with my presentation but when I built it again in a new presentation it all seemed to work fine. However, I will have to look into your solutions too. Thank you John.

We will call this one solved.