Consulting

Results 1 to 4 of 4

Thread: Random SlideShow Powerpoint

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Posts
    67
    Location

    Random SlideShow Powerpoint

    Hi everyone,

    First post here! I'll try to keep it clean! I promise!

    I am trying write a macro that makes a random Slideshow out of a Presentation. Downloading an AddIn that does it is not an option (Specially if it's not freeware).

    Here is the code I wrote.
    What does it do?
    0. There is an open presentation.
    1. Build an array containing the ID's of the slides of the presentation.
    2. Shuffle the array containing the ID's.
    3. Create a NamedSideShow.
    4. Run it.
    5. Delete the NamedSlideShow ( I don't know if it really deletes it).

    The problem is that even when it randomly Shuffles the array, the NamedSlideShow created seems to have the order of the slides of the presentation (Not Shuffled).

    Any Idea of how to do that?


    Sub RandomSlideShow()
    Dim numSlides As Integer
    Dim i As Integer
    numSlides = ActivePresentation.Slides.Count 'Counts the number of Slides of the presentation
    Dim qSlides() As Long 'Dynamically created
    ReDim qSlides(1 To numSlides) As Long '
    'Store the ID of every slide in qSlides
    For i = 1 To numSlides
        qSlides(i) = ActivePresentation.Slides.Item(i).SlideID
    Next
    ArrayShuffle (qSlides) 'Randomizes the positions of the slides ID.
    With ActivePresentation.SlideShowSettings
        .NamedSlideShows.Add "Show Random", qSlides
        .RangeType = ppShowNamedSlideShow
        .SlideShowName = "Show Random"
        .AdvanceMode = ppSlideShowUseSlideTimings
        .Run
        .NamedSlideShows.Item("Show Random").Delete
    End With
    End Sub
    Next Doubts:

    In the future I would like to create some kind of keyboard event so that when a certain key was pressed the presentation would continue without the slide. Any Guideline/ Idea?
    Last edited by Aussiebear; 04-28-2023 at 01:14 AM. Reason: Adjusted the code tags

  2. #2
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location
    Hi
    The following doesn't answer all your queries but it does shuffle slides and play them in the shuffled order! The number of 'shuffles' etc can be altered.

    Sub RandomSlides()
    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)
    intSlideCount = Application.ActivePresentation.Slides.Count
    intSlideCount = intSlideCount - 2
    ' Initialize random-number generator.
    Randomize
    'Repeat the random change 10 times
    For intLoopCounter = 0 To 10
        ' 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
    'Move to next slide
    SlideShowWindows(Index:=1).View.Next
    End Sub
    You might be able to adapt this to fit your presentation
    Last edited by Aussiebear; 04-28-2023 at 01:15 AM. Reason: Adjusted the code tags

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Posts
    67
    Location
    Thanks lion, but doesn't it alter the presentation?
    I would like it to remain the same.

    Anyway, I am curious to know what does this line mean
    SlideShowWindows(Index:=1).View.Next
    Last edited by Aussiebear; 04-28-2023 at 01:16 AM. Reason: Adjusted the code tags

  4. #4
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location
    Yes it does alter the order of the presentation - this did not matter for my project - I just wanted the slides to be played in a different order each time I ran the presentation. If you need to keep the original order, the code won't help.

    The last line just took me to the next slide - ignore it!

Posting Permissions

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