PDA

View Full Version : Powerpoint Quiz VBA Error - 1 is not in the valid range of 1 to 0



michaelja22
01-30-2014, 02:32 AM
Hi, I'm working on building a small quiz in Powerpoint 2007, using some code I found online (this is my first post so the site won't let me share links :think:).
I'm trying to adapt it so that there are more questions, and more possible answers (16 questions, 4 answer choices), but it still re-uses the same slide for each question.
This quiz is to go at the end of a training presentation, so slide numbers are much higher than just 1, 2 & 3.
The problem I'm having is that the code simply doesn't work properly, whenever I try to run it I get the errors "Subscript is out of range" or "1 is not in the valid range of 1 to 0" and the debugger highlights this line:

SlideShowWindows(1).Presentation.Slides("QSlide").Shapes("Question").TextFrame.TextRange.Text = Qs(QNo - 1)

Can anybody explain to me what's wrong here? I've never used VBA before and thought it should be a simple case of changing a few values to increase the number of questions etc and redesign the slides. I'm happy to share the code or upload the file if that would help.

Thanks in advance for any help offered.
:banghead:

John Wilson
01-31-2014, 01:44 AM
I would definitely share the presentation.

mancubus
02-02-2014, 10:49 AM
you can attach your file. click go advanced. scroll down. manage attachments.

Paul_Hossler
02-02-2014, 06:28 PM
A quick guess (aka shot in the dark) is that you probably want to change



SlideShowWindows(1).Presentation.Slides("QSlide").Shapes("Question").TextFr ame.TextRange.Text = Qs(QNo - 1)



to



SlideShowWindows(1).Presentation.Slides(QSlide).Shapes("Question").TextFr ame.TextRange.Text = Qs(QNo - 1)


if QSlide is a Long or Integer variable and you've not named the slides (and the shapes)


Paul

John Wilson
02-06-2014, 02:42 AM
As Paul says .Slides("QSlide") should probably be .Slides(QSlide) but this would not throw the error you see. Are you definitely running this in slide show mode because it would throw the error in edit mode.

If you just need a 16 question quiz with 4 choicves there are MUCH easier ways than using arrays BTW.

michaelja22
02-06-2014, 03:25 AM
Thanks for the advice guys. I have tried removing the quotation marks around QSlide as suggested, and still no dice I'm afraid.

I thought I was in Slideshow mode, but you have me doubting that now. Isn't it just a case of hitting F5 or Shift+F5?

Also, what are these easier ways than arrays? The reason I was working with this template is to keep the number of slides to a minimum, but if you know a better way I'm all ears. My Google searches just kept returning quizzes where there are 3 slides per question (i.e. question slide, congrats-right-answer slide and wrong-try-again slide).

I'm trying to upload the presentation, but for whatever reason it won't let me. Perhaps it's because I'm new to the forum and my macros aren't considered trustworthy.

John Wilson
02-06-2014, 03:55 AM
There's a very simple vba quiz template on our server

Here (http://www.pptalchemy.co.uk/Downloads/quiz.pptm)

If you cannot upload your quiz email it to me john ATSIGN pptalchemy.co.uk and I will post it.

John Wilson
02-07-2014, 06:45 AM
I got the Quiz from Michael.

It was downloaded from Shyam Pillai's site and Shyam really intended the provided slides to be re-used.

Michael had made his own slides. They just needed to be named "QSlide" and "Quiz Complete" and then it worked.