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. ("
' Commons Deed @
' License Legal @
' Purpose : Create and run a random slide show.
' Author : Jamie Garroch
' Date : 25MAR2020
' Website :
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
    ' 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.Add "Random", aSlides
      .ShowType = ppShowTypeSpeaker
      .LoopUntilStopped = msoTrue
      .RangeType = ppShowNamedSlideShow
      .SlideShowName = "Random"
    End With
  End With
  On Error GoTo 0
End Sub

' ShuffleArrayInPlace
' This shuffles InArray to random order, randomized in place.
' Source:
Private Sub ShuffleArrayInPlace(InArray() As Variant)
    Dim N As Long
    Dim Temp As Variant
    Dim J As Long
    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!

Roll the dice

In this downloadable example, you can click a button in the ribbon to randomly roll the 3D PowerPoint dice.

Animated Gif of a 3D dice

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.

Got something extra you’d like PowerPoint to do?

Check out our PowerPoint automation service which provides you with a custom solution to your specific needs.

Leave a comment
Written by

Jamie Garroch

Principal technical consultant

View Jamie Garroch's profile

Related articles

  1. Image of Paul Stadnyk Paul Stadnyk says:

    This is great, thanks for sharing. I am a bit of a novice with VB and I’m trying to modify your code slightly for my own purposes. But, I cannot make it do what I need. Perhaps you could suggest how I could do these two things:

    1) specify a range of slides to use (as opposed to all of them)
    2) trigger the macro from a button (or only when advancing to a specific slide within the range)

    Many thanks

    • Image of Jamie Garroch Jamie Garroch says:

      Hi Paul and thanks for the questions. For the first, you’d need to modify how the array of slides is created which currently uses this bit of the code:
      For Each oSld In .Slides
      aSlides(oSld.SlideIndex) = oSld.SlideID
      The question then is “how will the range of slides be determined?” For the second part, you can trigger a publicly declared Sub procedure from a shape on a slide during a slide show by using the Insert / Links / Action / Run Macro feature in the PowerPoint ribbon. The challenge here is that the slide show is already running so calling the RunRandomSlideShow macro won’t do what you want. That makes a solution quite complex and not easy to provide here. If you would liek us to take a look at this as a project, please send us a message in the Contact page mentioning me.

  2. Image of Ben Newman Ben Newman says:

    I have been looking for something like this and was having trouble.
    I am an educator and I like to show my students flashcards and wanted to randomize the flashcards.
    A colleague of mine sent me to this site.
    This is very helpful – thank you!

  3. Image of Sharon Sharon says:

    Love thus! Creating materials for k teachers. Been writing a new one for each randomize. Its perfect for creating a lesson say learning counting numbers and then randomizing the flashcards for practice. I’ll try this now!

  4. Image of S Mason S Mason says:

    I copied your macro exactly, but it doesn’t run a new random order each time. It did a random order the first time, but each subsequent time, it ran the slides in the same mixed order as the first time, so it is no longer random. I tested this in various ways, including closing the file and the app and re-opening it, but I still got the same order.

    I thought I followed the instructions perfectly, but perhaps I missed something? I have reviewed and can’t see anything I missed.


    • Image of Jamie Garroch Jamie Garroch says:

      Hi S Mason. Are you running the macro each time or just running the slide show? Once the VBA code is in your file you should be able to close the VBE and run it by pressing Alt+F8 which creates a new random order and starts the slide show.

      • Image of Kristi Kristi says:

        So you have to run the slide show using Alt+F8 in order to have it run a new random order each time? Just want to clarify.

  5. Image of James James says:

    Is it possible to have this kind of presentation including the macros publish on a Webpage?

    • Image of Jamie Garroch Jamie Garroch says:

      Hi James. Office content that contains macros only work on the desktop versions of their applications for Windows and macOS. You can however create interactivity within your presentation and publish as web-compatible HTML5 using the iSpring plug-in.

      • Image of james james says:

        Hi Jamie,
        Many thanks for your advice. I find it useful and I will update you on my progress and findings.

        Kind regard

  6. Image of dare dare says:

    Hi Jamie,
    Your code is inspirational. I am developing randomized slides with powerpoint 2016. My presentation has multiple questions on each page and require answers from my students. I have two questions.
    1.) Once I get this up and running I will like to have it on a webpage. What do I have to do to achieve this?
    2.) Currently, I have the presentation saved as pptm.

    Any thoughts.

    • Image of Jamie Garroch Jamie Garroch says:

      See above James. I think iSpring could be your best option.

  7. Image of Kristi Kristi says:

    What exactly am I copying into the Module box in PowerPoint? Everything from above (blue, black, & green font?) starting with “option” and ending with “end sub?” I am a complete newb, obviously & trying to randomize some flashcards for speech students. Also, does this just run automatically or do I click “next” or whatever to advance to the next slide (preferred method)? Thank you.

    • Image of Jamie Garroch Jamie Garroch says:

      That’s right Kristi. All that you described is the code. The colours just indicate the meaning of various elements eg. green represents comments. Once your flash cards have been randomised you could either click next (or space-bar or return or arrow keys) manually, or go to the transition tab and set a time on the right hand side of the ribbon to automatically advance each slide.

  8. Image of Lee Harbula Lee Harbula says:

    This is CLOSE to what I wanted… but not quite.

    What I want is to be able to create short PowerPoints (3 to 10 slides each).
    Create multiple Power Points and make a list of the PowerPoints.
    Then have the PowerPoint presentations run in random order on a continuous loop.

    I have a “Safety Vision” display monitor set up so that employees can watch a presentation at their leisure during the workday. I have been using the “Safety Vision” to present a 5 minute loop of ONE PowerPoint, but it has been suggested that a 30 to 60-second loop followed by a DIFFERENT 30-60 second loop may go over better. If I can show a list of multiple presentations would be good… to do so in a random order would be even better.

    • Image of Jamie Garroch Jamie Garroch says:

      That’s certainly doable with VBA although quite complex as multiple files need to be managed. I wonder if an alternative method could be to create all the content in a single file and then create Custom Slide Shows for each. Then you could write some VBA code to randomize the order of the custom shows.

  9. Image of Julie Dirks Julie Dirks says:

    Thank you from the bottom of my heart! I just took a “manual” math bingo game displaying geometry figures as the caller cards that I am using as a review before the test and easily converted it to a randomized bingo game. I can easily run this from the promethean board (massive touchscreen computer) at the front of my math class room! Perfect!

    • Image of Jamie Garroch Jamie Garroch says:

      Great to hear you’ve found a practical use for this Julie 🙂

  10. Image of Hamilton R. Hamilton R. says:

    Hi Jamie, nice tip with lots of potential applications.

    Just curious: have you thought of developing random CrossFit workouts using a modification of the technique?

    It would be great to have gifs in slides and a timer for say 40 seconds. Once the slide gets active, the timer starts countdown and the gif shows the exercise.

    then a transition of say 15 seconds, to another slide.

    That way one can have a workout of the day which varies and plays so that all one does is follow along.

    Duration can vary from 8 to 40 minutes (the whole set of exercises), and the exercises may vary between weightlifting, gymnastics, calisthenics, obstacle race type, cardio (machines), strongman, etc.

    I would think there would be a commercial interest in the product now that many need to take training home.

    • Image of Jamie Garroch Jamie Garroch says:

      Hi Hamilton. There are certainly lots of potential uses for this as it stands and of course it could be extended to all sorts of other applications as you described. We typically don’t make products out of presentations but you could take this free sample and develop it further for other use cases.

  11. Image of Samio Samio says:

    just what I want..
    Thanks a lot

  12. Image of Kathleen Kathleen says:

    Thanks for this! I am running a training online that I usually do in person, and this is enabling me to use ppt like a deck of cards 🙂

    • Image of Jamie Garroch Jamie Garroch says:

      That’s great to hear Kathleen and thank you so much for letting us know you’re finding it useful.

  13. Image of Barbara Jenkins Barbara Jenkins says:

    This is wonderful and incredible and thank you for sharing it!

Join the BrightCarbon mailing list for monthly invites and resources

Tell me more!

First of all the deck looks great, once again you guys have done an outstanding job. Second, I’d like to comment on the quality of the training provided by your colleagues - quite simply it was exceptional. I have spoken to the whole team and that view is unanimous. Please pass this on.

James Bagan MyLife Digital