Consulting

Results 1 to 5 of 5

Thread: VBA coding help

  1. #1
    VBAX Regular
    Joined
    Nov 2009
    Posts
    7
    Location

    VBA coding help

    Hi

    I was wondering if anyone could help me. I am trying to create a quiz in Powerpoint 2007 and i want to be able to have a running total. I have a created three macros to help keep a running total but the line of code to make it move to the next slides is not working.

    The macros are below, the correct macro is on each of the correct answers and the Initalise macro is attachted to the start here button. Can anyone tell me why its not working?

    Sub Initialise()
    ActivePresentation.SlideShowWindow.View.Next
    NumberCorrect = 0
    End Sub
    Sub Correct()
    ActivePresentation.SlideShowWindow.View.Next
    NumberCorrect = NumberCorrect + 1
    End Sub
    Sub Display()
    MsgBox ("You got " & NumberCorrect & " questions right")
    End Sub

    Thank you

    Jess

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    First are you sure macros are running?

    Second
    ActivePresentation.SlideShowWindow.View.Next

    Doesn't necessarily take you to the next slide. It takes you to the next bulid which may be an animation

    This will take you to the next slide

    [VBA]i = SlideShowWindows(1).View.CurrentShowPosition + 1
    If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Nov 2009
    Posts
    7
    Location
    Hi

    Thank you for replying. The solution you provided me with is working great thank you.

    However the count i have on the macros which keeps a running total on the quiz does not work and i am not sure why. Is it possible you could help me with this?

    The line of code i have used to keep a running total is highlighted below:

    Sub Initialise()
    i = SlideShowWindows(1).View.CurrentShowPosition + 1
    If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)

    NumberCorrect = 0
    End Sub
    Sub Correct()
    i = SlideShowWindows(1).View.CurrentShowPosition + 1
    If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)

    NumberCorrect = NumberCorrect + 1
    End Sub
    Sub Display()
    MsgBox ("You got " & NumberCorrect & " questions right")
    End Sub

    Thank you

    Jess

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Hi Jess

    To prevent the NumberCorrect variable being reset you need to declare it outside of all subs but in the same module.

    Like this

    [vba]Dim NumberCorrect As Integer

    Sub Initialise()
    i = SlideShowWindows(1).View.CurrentShowPosition + 1
    If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)
    NumberCorrect = 0
    End Sub
    Sub Correct()
    i = SlideShowWindows(1).View.CurrentShowPosition + 1
    If i < ActivePresentation.Slides.Count Then SlideShowWindows(1).View.GotoSlide (i)
    NumberCorrect = NumberCorrect + 1
    End Sub
    Sub Display()
    MsgBox ("You got " & NumberCorrect & " questions right")
    End Sub[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Regular
    Joined
    Nov 2012
    Location
    Alaska
    Posts
    22
    Location
    can i get a copy of your exam?

Posting Permissions

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