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
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