Not too long ago (in a galaxy far far away) I was contacted by a friend in order to help him randomize a PowerPoint for the purpose of what would be essential flash cards. He needed a way to randomize 3 different types of PowerPoints. When this was first described to me in a brief phone conversation I told him that this would be a quick and simple task. Now never having worked in Visual Basic let alone within an office product this proved to be a little bit more difficult then I thought. However I am a reasonably competent C# .NET developer so it’s not like I was exactly swinging in the dark. So as I discussed this problem he had further here is what I found out about the three PowerPoints he needed randomized.

Type I – Complete Randomization

This was a very straight forward request. One very easily solved with a quick Google search. Having this is a crash course into VB.NET was just what I needed to gear be up for the next ones.

Type II – 3 Series Randomization

This is where it began to become a little bit trickier. I will leave some details out here as I will be explaining a similar concept in the next Type, but in short there are 30 slides in total, which were divided into 10 groups of 3. Each group has to have a static card first and then the two following cards must be randomized. After each group has been randomized individually the groups (kept intact) but then be randomized. Now there is some easy logic to this but as I will explain where I ran into the most problems.

Type III – 5 Series Randomization

**The Problem:** Here is where I will spend the most of this tutorial talking about the logic and VB necessary to complete the described problem. In a PowerPoint of 50 slides there are 10 groups of 5 slides wherein the first slide is always static, the following four are to be randomized and each group of 5 (kept intact) are then randomized.

**Other Issues:** Here are some of the problems I faced when trying to complete this in PowerPoint.

1 – There are no distinguishing names for slides in PowerPoint other then the position that they current exist. This causes a problem when trying to randomize a slide to somewhere else within a PowerPoint while keeping its other 4 slides in coherency.

2 – VB cannot support selecting multiple slides and moving them together. In the way you might think of selecting several slides by clicking, holding down shift and selecting another slide to grab a series of slides.

3 – When using VB you can either use the Cut and Paste method or you can use the MoveTo method in which you set the slide to move and the location it is to move. The problem or rather I should say the stumbling block is understanding that when you do either of these methods you must account for the fact that when a slide is moved the slide that it is moving to is going to shift down. Meaning that the location that you plan to move the slide must be offset in this consideration.

**The Solution:** Unfortunately I had a very short time table to complete this for him and being unfamiliar with VB had put me in a position that I had to make this code tailor made for his PowerPoint but the principal is still there.

In completion this script should work in two loops. The first loop will keep alpha slide static and then proceed to randomize the following 4 slides.

The second loop will then create a random number that will determine how many times to; select slide 1, copy it, then paste on the alpha slide of the last group.

Before I hear “OHH Justin that’s not very random, you are just shuffling the slide order x amount of times”, yes that is true but this became an ideal solution for my friend so we kept it. Another potential solution to making this random would be to use that same shuffle method in two places (i.e. group 1 alpha 1 and group 3 alpha 1).

Well without further painstaking explanation here is an example of the code:

Sub Random5()
'For x = 1 To 4 (cycles 4 times for for slides)
'rng = Int((HighestNumber - LowestNumber + 1) * Rnd) + LowestNumber
'ActivePresentation.Slides(rng).MoveTo LowestNumber
'Next (part of for loop)
For x = 1 To 4
rng = Int((5 - 2 + 1) * Rnd) + 2
ActivePresentation.Slides(rng).MoveTo 2
Next
For y = 1 To 4
rng = Int((10 - 7 + 1) * Rnd) + 7
ActivePresentation.Slides(rng).MoveTo 7
Next
For z = 1 To 4
rng = Int((15 - 12 + 1) * Rnd) + 12
ActivePresentation.Slides(rng).MoveTo 12
Next
rng2 = Int((5 - 1 + 1) * Rnd) + 1
For w = 1 To rng2
For v = 0 To 4
ActivePresentation.Slides(1).Select
ActiveWindow.Selection.Cut
ActivePresentation.Slides(ActivePresentation.Slides.Count).Select
ActiveWindow.View.Paste
Next
Next
End Sub

Feel free to make any comments, ways to improve or if you have any questions I will be happy to answer.