PDA

View Full Version : Solved: Random slides except 1st and last



jmaocubo
05-29-2012, 07:57 AM
Hello all

I was looking at the site for the code "random slideshow". But I only found the code that random slides except the 1st slide.
How can I do to avoid the shuffle on the 1st and the last slide?

I'm using:
Sub aleatorio()
Dim intSlideCount As Integer
Dim intRandomCut As Integer
Dim intRandomPaste As Integer
Dim intLoopCounter As Integer
'Count number of slides excluding the first two (don't want these shuffled)
'.Slides.Count - 1
intSlideCount = Application.ActivePresentation.Slides.Count
intSlideCount = intSlideCount - 2
' Initialize random-number generator.
Randomize
'Repeat the random change 8 times
For intLoopCounter = 0 To 8
' Generate random value between 3 and last slide.
intRandomCut = Int((intSlideCount * Rnd) + 3)
intRandomPaste = Int((intSlideCount * Rnd) + 3)
'Move a randomly chosen slide from 1 position to another
ActivePresentation.Slides(intRandomCut).MoveTo toPos:=intRandomPaste
Next

End Sub
Thanks in advance

Miguel

John Wilson
05-29-2012, 09:04 AM
Have a look at the shuffle code here (http://www.pptalchemy.co.uk/vbasamples.html)

jmaocubo
05-30-2012, 08:45 AM
Have a look at the shuffle code here (http://www.pptalchemy.co.uk/vbasamples.html)

Thanks John Wilson it works fine........... :friends:

John Wilson
05-30-2012, 11:01 AM
That's good. This code will do as you say with no user input.

Sub shuffle_not_Top_Bottom()
Dim oPres As Presentation
Dim LCount As Long
Dim LTo As Integer
Dim LFrom As Integer
Dim L As Long
Set oPres = ActivePresentation
LCount = oPres.Slides.Count - 2
Randomize
For L = 1 To LCount * 3
LTo = Int(Rnd * (LCount)) + 2
LFrom = Int(Rnd * (LCount)) + 2
Debug.Print LTo & LFrom
oPres.Slides(LFrom).MoveTo (LTo)
Next
End Sub