printable slide VBA for Random questions

B

Bonnie

I have been going through the book, Powerful PowerPoint for Educators, and
wanted to have both random questions and a printable slide. My code works to
the point of adding the printable slide. However, it does not show the slide
until I get out of the slide show view and then there are no buttons. Any
ideas. The code is below:

Dim numCorrect As Integer
Dim numIncorrect As Integer
Dim username As String
Dim visited() As Boolean
Dim numSlides As Long
Dim numRead As Integer
Dim numWanted As Integer
Dim printableSlideNum As Long
Sub GetStarted()
Initialize
YourName
RandomNext
End Sub
Sub Initialize()
Randomize
numCorrect = 0
numIncorrect = 0
numWanted = 10
numRead = 0
numSlides = ActivePresentation.Slides.Count
ReDim visited(numSlides)
For i = 2 To numSlides - 1
visited(i) = False
Next i
printableSlideNum = ActivePresentation.Slides.Count + 1
End Sub
Sub YourName()
username = InputBox("What is your name?")
End Sub
Sub RightAnswer()
If qanswered = False Then
numCorrect = numCorrect + 1
End If
qanswered = False
DoingWell
visited(ActivePresentation.SlideShowWindow.View.Slide.SlideIndex) = True
numRead = numRead + 1
RandomNext
End Sub
Sub WrongAnswer()
If qanswered = False Then
numIncorrect = numIncorrect + 1
End If
qanswered = False
DoingPoorly
visited(ActivePresentation.SlideShowWindow.View.Slide.SlideIndex) = True
numRead = numRead + 1
RandomNext
End Sub
Sub DoingWell()
MsgBox ("Good job, " & username & ".")
End Sub
Sub DoingPoorly()
MsgBox ("Try to do better next time, " & username & ".")
End Sub
Sub RandomNext()
Dim nexSlide As Long

If numRead >= numWanted Or numRead >= numSlides - 2 Then
ActivePresentation.SlideShowWindow.View.Last
Else
nextSlide = Int((numSlides - 2) * Rnd + 2)
While visited(nextSlide) = True
nextSlide = Int((numSlides - 2) * Rnd + 2)
Wend
ActivePresentation.SlideShowWindow.View.GotoSlide (nextSlide)
End If
End Sub
Sub Feedback()
MsgBox ("You got " & numCorrect & " out of " _
& numCorrect + numIncorrect & ", " & username)
End Sub
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 = _
"You got " & numCorrect & " out of " & _
numCorrect + numIncorrect & "." & Chr$(13) & _
"Press the Print Results button to print your answers."
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 = _
ActivePresenation.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

Thanks,

Bonnie
 
D

David M. Marcovitz

Bonnie,

This is great. You are going to kick yourself when I tell you what the
problem is. For the future, you might want to check out the section in
Chapter 9 about debbugging tips. The key tip that could have saved you is
the one about capitalization. If you don't capitalize when you type most
of your code, you will find errors like this more easily. Your code works
perfectly if you replace

ActivePresenation

with

ActivePresentation

I told you were going to kick yourself. The mistake is in the
PrintablePage procedure on the line right after Set printButton.

This is a great variation on my examples. I hope you'll send it to me for
inclusion on the Web site when you are done.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
B

Bonnie

hanks so much. That fixed the problem. I would kick myself except that I'm
old enough to know now that it is not worth it for little things.

You book is quite helpful. Being new to programming, though, has given me a
huge learning curve. Also, I'm the first at my workplace to work from your
book, so I have to work out things for myself.

Chapter 9 is proving to be helpful. However, I know that debug is always
going to stop on ActivePresentation because it is not in slide show view
when I run it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top