Consulting

Results 1 to 4 of 4

Thread: Solved: Random slides except 1st and last

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    69
    Location

    Solved: Random slides except 1st and last

    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:
    [vba]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[/vba]
    Thanks in advance

    Miguel

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Have a look at the shuffle code here
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Aug 2009
    Posts
    69
    Location
    Quote Originally Posted by John Wilson
    Have a look at the shuffle code here
    Thanks John Wilson it works fine...........

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    That's good. This code will do as you say with no user input.

    [VBA]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[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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