VBA slide reference

D

Dianne Aldridge

I'm trying to run a simple set of 5 quiz slides and display a printable
slide at the end with the score (I will be adding more slides later;
David, if you're reading this, I'm just trying to put together a quick
& dirty show to display all of my quiz questions for retention testing
at the end of my ARP). After each question is answered, I want to
determine whether or not it is the last question slide; if yes, go to
the printable slide, if no, go to the next slide.

I'm having trouble determining what is the best method to use to
determine if it is the last question slide. I will know the exact slide
number, so I tried to use ActivePresentation.Slide.Count, but it does
not work, I'm never taken to the printable page. I think perhaps I
should use the slide number instead of the count, but I'm not sure of
the syntax for the statement; how to I check for slide #6? I downloaded
Microsoft's VBA reference for PowerPoint to see if it would provide
that information, but it's made for real programmers, not scripters
like me.

Here's my code:

Dim StudentName As String
Dim HaveName As Boolean
Dim NCAirplane As Integer
Dim NIAirplane As Integer
Dim printableSlideNum As Long
Sub Start()

NCAirplane = 0 'number correct
NIAirplane = 0 'number incorrect
printableSlideNum = ActivePresentation.Slides.Count + 1

HaveName = False
While Not HaveName
StudentName = InputBox(prompt:="Please type your name in
the space below", Title:="Student Name")
If StudentName = "" Then
HaveName = False
Else
HaveName = True
End If
Wend

ActivePresentation.SlideShowWindow.View.GotoSlide (2)

End Sub
Sub RightAnswerAirplane()

NCAirplane = NCAirplane + 1
If ActivePresentation.Slide.Count = 6 Then
PrintablePage
End If

ActivePresentation.SlideShowWindow.View.Next

End Sub
Sub WrongAnswerAirplane()

NIAirplane = NIAirplane + 1
If ActivePresentation.Slide.Count = 6 Then
PrintablePage
End If

ActivePresentation.slideshowindow.View.Next

End Sub
Sub PrintablePage()

' printableSlideNum = ActivePresentation.Slides.Count + 1
Dim printableSlide As Slide

Set printableSlide =
ActivePresentation.Slides.Add(Index:=printableSlideNum, _
Layout:=ppLayoutText)
printableSlide.FollowMasterBackground = msoFalse
printableSlide.Background.Fill.ForeColor.RGB = vbWhite
printableSlide.Shapes(1).TextFrame.TextRange.Text = "Retention
Results for " & StudentName
printableSlide.Shapes(2).TextFrame.TextRange.Text = _
"Airplane Quiz: " & 100 * NCAirplane / (NIAirplane +
NCAirplane) & "%"
ActivePresentation.SlideShowWindow.View.GotoSlide.printableSlideNum
ActivePresentation.Saved = True

End Sub
 
D

David M. Marcovitz

Instead of:

Sub RightAnswerAirplane()

NCAirplane = NCAirplane + 1
If ActivePresentation.Slide.Count = 6 Then
PrintablePage
End If

ActivePresentation.SlideShowWindow.View.Next

End Sub


You want:

Sub RightAnswerAirplane()

NCAirplane = NCAirplane + 1
If ActivePresentation.SlideShowWindow.View.Slide.SlideIndex = 6 Then
PrintablePage
Else
ActivePresentation.SlideShowWindow.View.Next
End If
End Sub

Or better yet, replace 6 with printableSlideNum - 1 if it always comes
before the last slide.

Alternatively, just use Example 8.11 on my site which allows you to add
as many multiple-choice questions as you want without changing the code.

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

David M. Marcovitz

I also forgot to mention (although it is probably obvious), you need to
change the WrongAnswer procedure in the same way as the RightAnswer
procedure.
--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/
 
D

Dianne Aldridge

David,
All works except that the PrintablePage subrountine will not execute
after answering the question on slide 6. I tried it using the slide
index number and printableSlideNum -1. Any ideas? This is not
difficult code at all, but I don't see it. Here's what I have now:

Sub RightAnswerAirplane()

NCAirplane = NCAirplane + 1
If ActivePresentation.SlideShowWindow.View.Slide.SlideIndex =
printableSlideNum - 1 Then
PrintablePage
Else
ActivePresentation.SlideShowWindow.View.Next
End If

End Sub
Sub WrongAnswerAirplane()

NIAirplane = NIAirplane + 1
If ActivePresentation.SlideShowWindow.View.Slide.SlideIndex =
printableSlideNum - 1 Then
PrintablePage
Else
ActivePresentation.SlideShowWindow.View.Next
End If
End Sub
 
D

David M. Marcovitz

I don't see anything wrong with your code, other than the line breaks,
but I assume they were put in by the news system and aren't really in
your code. If you don't have line breaks on the If lines (putting
printableSlideNum - 1 on the next line), then you'll have to put some a
MsgBox or two in your code to try to see what is going on.

Also, one more thing. I assumed that the last question was on the last
slide (thus it would be just before the place where you planned to add
the printable page). If that is not the case then just use the number
instead of printableSlideNum - 1.

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

Dianne Aldridge

David,
Thanks for suggesting using Msgboxes - that really helped a lot. I
found out that the PrintableSlide routine IS executing -- the slide is
being created -- the code is just not taking me to the slide. Funny,
this is the exact same code I used in the individual lessons; I
copy/pasted. Is there another way to go directly to the printable
slide? Guess I could try .GotoSlide (7) - but I shouldn't have to.

I even thought for a minute that those animated .gifs might be causing
some trouble for some reason and removed the ones on the last question
slide, but the show did not advance to the printable slide.

So now what happens is the show remains on the last question slide,
while in the background the printable slide is created and correct. I
see nothing wrong with my code - but obviously something is! I would
start to pull my hair out, but I'm already prematurely gray, so I'd
better just hope someone has an idea. :)

Sub PrintablePage()

Dim printableSlide As Slide

Set printableSlide =
ActivePresentation.Slides.Add(Index:=printableSlideNum, _
Layout:=ppLayoutText)
printableSlide.FollowMasterBackground = msoFalse
printableSlide.Background.Fill.ForeColor.RGB = vbWhite
printableSlide.Shapes(1).TextFrame.TextRange.Text = "Retention
Results for " & StudentName
printableSlide.Shapes(2).TextFrame.TextRange.Text = _
"Airplane Quiz: " & 100 * NCAirplane / (NIAirplane +
NCAirplane) & "%"
ActivePresenation.SlideShowWindow.View.GotoSlide.printableSlideNum
ActivePresentation.Saved = True

End Sub

Of course, printableSlideNum is defined at the start:
printableSlideNum = ActivePresentation.Slides.Count + 1
 
D

David M. Marcovitz

ActivePresenation.SlideShowWindow.View.GotoSlide.printableSlideNum

should be:

ActivePresentation.SlideShowWindow.View.GotoSlide printableSlideNum

That is space, instead of period before printableSlideNum (and a "t" in
ActivePresentation). I'm guessing you copied and pasted the code from an
earlier message of mine because those look like typos I would make when
answering a question with testing the code. You could put parentheses
around printableSlideNum because I put parentheses around everything in
the book, but parentheses are not necessary, except possibly to keep you
from typing the period:)

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

Dianne Aldridge

David,
I think that perhaps I should use the parenthesis - perhaps that will
keep me from wasting your time finding my syntax errors! Actually, I
really thought a period went before printableSlideNum, so I probably
wouldn't have caught that one (why didn't Debug highlight that error?).
It's the missing "t" in ActivePresentation that is downright
embarrassing. I don't think I could ever program for a living - I don't
have the patience and I obviously don't have the talent....did I ever
tell you the story about searching hours for one missing period in an
old COBOL program of mine? Don't get me started...... :)

Thanks -- all works well now.
 

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