-
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? :dunno
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
-
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]
-
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
-
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]
-
can i get a copy of your exam?