PDA

View Full Version : Make random slides code run as slide show starts



duke99
10-23-2012, 10:23 AM
Hi Guys,

i found 2 Scripts. (1. by John Wilson - Make code run as slide show starts)
vbaexpress_com/kb/getarticle.php?kb_id=983
and the 2. on an other website. And I didn't get it work like this:

My Idea was run the "sort_rand"-Script everytime i hit "F5" so that my slide always sort randomly at the start of an presentation.
This is important for me because there are Questions on every slide with answers to learn. And this would help me very much. Does anybody know how to do that?

Thanks for your help and time,
duke99


Script 1:

Sub OnSlideShowPageChange()
Dim i As Integer
i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
If i <> 1 Then Exit Sub
MsgBox "Your code goes here"
End Sub


Script 2:

Sub sort_rand()

Dim i As Integer
Dim myvalue As Integer
Dim islides As Integer
islides = ActivePresentation.Slides.Count
For i = 1 To ActivePresentation.Slides.Count
myvalue = Int((i * Rnd) + 1)
ActiveWindow.ViewType = ppViewSlideSorter
ActivePresentation.Slides(myvalue).Select
ActiveWindow.Selection.Cut
ActivePresentation.Slides(islides - 1).Select
ActiveWindow.View.Paste
Next

End Sub

johnwatkins3
11-15-2012, 02:36 PM
so with this with a button on the first slide that says "begin" then it would begin quiz and also randomize the quiz questions.

duke99
11-15-2012, 03:02 PM
Yes that's what I need. But I don't know how... :-)

johnwatkins3
11-15-2012, 10:53 PM
thats what im working on also

John Wilson
11-15-2012, 11:25 PM
The OnSlideShowPagechange code SHOULD run every time the slide changes. It isn't totally reliable though. A button on slide 1 will always work.

I would never use code that selects and cuts and pastes . There's no need as PowerPoint has a MOVE slide method. This code shuffles slides 2 - 5, change the numbers to the slides you need.


Sub shufflerange()
Dim Iupper As Integer
Dim Ilower As Integer
Dim Ifrom As Integer
Dim Ito As Integer
Dim i As Integer
Iupper = 5
Ilower = 2
If Iupper > ActivePresentation.Slides.Count Or Ilower < 1 Then GoTo err
For i = 1 To 2 * Iupper
Randomize
Ifrom = Int((Iupper - Ilower + 1) * Rnd + Ilower)
Ito = Int((Iupper - Ilower + 1) * Rnd + Ilower)
ActivePresentation.Slides(Ifrom).MoveTo (Ito)
Next i
Exit Sub
err:
MsgBox "Your choices are out of range", vbCritical
End Sub

ALT f11 to open the VBEditor then insert module. Paste in the code. On slide one insert a shape and use INSERT Action to give it an action of RUN macro.

NOTE you need to click the button in SHOW mode.

madelinekim
04-22-2013, 02:54 AM
It is such a great to use this code in PowerPoint to make presentation access more better. When you want to play the presentation from starting then you can only press f5 and you can enjoy the presentation on important topics.