Now here’s a curious concept. Viewing your PowerPoint slide show in a completely random order. When everything we do here at BrightCarbon is about telling your stories more effectively with a logical and linear flow it might seem like a very strange thing to want to do. So why would you want to do this?

I love PowerPoint. There, I said it and I feel better as a result, just as my therapist told me I would. I use it to create all sorts of things from the obvious presentations, to print documents, videos and even animated GIF images. I love PowerPoint even more when I can get inside it and use VBA code to make it do stuff most people don’t even know is possible.

I recently organised a birthday party for my wife and, as I have a high-quality projector mounted on the ceiling, I thought it would be cool to have a slide show of pictures from across the years playing on the wall. But pictures weren’t enough, I wanted them to be ‘presented’ with an attractive design, a timeline indicator and captions. It was an obvious choice to use PowerPoint to design the content.

Screenshot of birthday slideshow slides

The completed presentation has one slide for each of my wife’s years, which will get me into a lot of trouble! Playing it back in order was ok but I wanted to mix it up and have the slides appear in a random order to make it a bit more interesting. Jumping from college years to a baby, to an adult, back to a teenager made it more interesting than running in a linear timeline.

There’s no native feature in PowerPoint that lets you run your slides in a random order. So, I opened up the VBE (Visual Basic Editor) built into PowerPoint and wrote a quick VBA macro to do it for me.

The macro does a couple of things. It firstly works out how many slides there are in the presentation and creates an array (a bit like a table of data) in which all of the unique slide IDs are stored. You might not know, but slides in PowerPoint have a couple of identities. The one we all know is the slide number. But that changes if you move the slide around the presentation. The next one is the slide ID and this is both unique and constant. It gets created when a new slide is added to the presentation and never changes, regardless of where the slide is in the presentation.

This array of slide IDs is then shuffled like a deck of cards using a randomise function. Finally, the randomised array is used to create a custom slide show that is then set to run. And the really cool bit is that every time the macro is run, you get a different slide order.

The full VBA (Visual Basic for Applications) macro is included below and if you need to know how to use it in your presentation then check out our How to use VBA in PowerPoint article. The comments in green tell you what each part of the macro is doing.

Option Explicit
Option Base 1

'----------------------------------------------------------------------------------
' PowerPoint VBA Macro to run a slide show in a random order.
'----------------------------------------------------------------------------------
' Copyright (c) 2020 BrightCarbon Ltd. All Rights Reserved.
' Source code is provided under Creative Commons Attribution License
' This means you must give credit for our original creation in the following form:
' "Includes code created by BrightCarbon Ltd. (brightcarbon.com)"
' Commons Deed @ http://creativecommons.org/licenses/by/3.0/
' License Legal @ http://creativecommons.org/licenses/by/3.0/legalcode
'----------------------------------------------------------------------------------
' Purpose : Create and run a random slide show.
' Author : Jamie Garroch
' Date : 25MAR2020
' Website : https://brightcarbon.com/
'----------------------------------------------------------------------------------
Public Sub RunRandomSlideShow()
  Dim oSld As Slide
  Dim aSlides() As Variant
  
  On Error Resume Next
  
  With ActivePresentation
    ReDim aSlides(.Slides.Count)
    
    ' Get a list of all of the slide IDs in the presentation
    For Each oSld In .Slides
      aSlides(oSld.SlideIndex) = oSld.SlideID
    Next
    
    ' Reorder the list of slides in a random order
    ShuffleArrayInPlace aSlides
    
    ' Create and run a custom slide show using the random order
    With .SlideShowSettings
      .NamedSlideShows("Random").Delete
      .NamedSlideShows.Add "Random", aSlides
      .ShowType = ppShowTypeSpeaker
      .LoopUntilStopped = msoTrue
      .RangeType = ppShowNamedSlideShow
      .SlideShowName = "Random"
      .Run
    End With
  End With
  
  On Error GoTo 0
  
End Sub

'----------------------------------------------------------------------------------
' ShuffleArrayInPlace
' This shuffles InArray to random order, randomized in place.
' Source: http://www.cpearson.com/excel/ShuffleArray.aspx
'----------------------------------------------------------------------------------
Private Sub ShuffleArrayInPlace(InArray() As Variant)
    Dim N As Long
    Dim Temp As Variant
    Dim J As Long
   
    Randomize
    For N = LBound(InArray) To UBound(InArray)
        J = CLng(((UBound(InArray) - N) * Rnd) + N)
        If N <> J Then
            Temp = InArray(N)
            InArray(N) = InArray(J)
            InArray(J) = Temp
        End If
    Next N
End Sub

Each time you run the RunRandomSlideShow macro you’ll see your slides appear in a slide show in a different order. When you quit your slide show, you can then see what the macro has done by clicking the Slide Show tab in PowerPoint.

First, click the Custom Slide Show menu and choose Custom Shows…

PowerPoint random slide show screenshot 2

This opens the Custom Shows window and you’ll see that a new custom show called Random has been created:

PowerPoint random slide show screenshot 4

If you select this custom show and then click the Edit button you’ll see all of your slides on the left hand side and the randomly ordered list of them on the right:

PowerPoint random slide show screenshot 5

Remember, each time you run the macro this order will change.

This is how the macro creates the random order slide show but how does it actually run it? Close the windows above and back in the PowerPoint Slide Show tab click the Set up Slide Show button. This opens up the settings for your slide show:

PowerPoint random slide show screenshot 6

Here you’ll see on the right hand side that instead of showing All your slides, the macro has instructed PowerPoint to run a Custom show called Random. It also set the show to Loop continuously until ‘Esc’ so that it never ends!

You could use the same technique to add some spice to your PowerPoint Karaoke – also known as PowerPoint Roulette or Battledecks – an improvisation game where you give a presentation to an audience without knowing the content of the slides!

There you have it. Now you can go out into the world and play random slide shows to your heart’s content. And if you want to know more about macros, check out our other VBA blog articles. If you’re interested in add-ins, we have a very cool free one called BrightSlide and should you be interested in having us develop a custom solution for you, get in touch here.

Leave a comment
Written by

Jamie Garroch

Senior technical consultant

View Jamie Garroch's profile

Related articles

Aug 2020

PowerPoint has evolved into an app which is the Swiss Army knife of content creation, not only for presentations but also printed collaterals, videos and even interactive presentations. In this second part of our series on supercharging PowerPoint interactive presentations with VBA we look at how you can provide your users with visual feedback for active areas of your slide using a mouse hover technique.

    Leave a Reply

    Join the BrightCarbon mailing list for monthly invites and resources

    Tell me more!

    You guys are amazing! Looks awesome, and works great. Perfect!

    Mila Johnson InComm