Consulting

Results 1 to 8 of 8

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

  1. #1

    Powerpoint Quiz VBA Error - 1 is not in the valid range of 1 to 0

    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 ).
    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").TextFr ame.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.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    I would definitely share the presentation.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you can attach your file. click go advanced. scroll down. manage attachments.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    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.

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    There's a very simple vba quiz template on our server

    Here


    If you cannot upload your quiz email it to me john ATSIGN pptalchemy.co.uk and I will post it.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •