0
votes

I am trying to figure out how i can shuffle the slides in one of my power point presentations when the presentation is opened.

I have the code, but trying to find out how to make it work as power point do not have event handlers. I have tried different solutions but cant get it to work.

I have tried with auto_open add-ins and also different codes but with no luck, thankful for any assistance

The code i want to run when the presentation is opened up by a user:

Sub shuffleRange()

Dim Iupper As Integer
Dim ilower As Integer
Dim ifrom As Integer
Dim Ito As Integer
Dim i As Integer

Iupper = 21
ilower = 2

If Iupper > ActivePresentation.Slides.Count Or ilower < 1 Then GoTo Err

For i = 1 To 2 * Iupper
Randomize
ifrom = Int((Iupper - ilower + 1) * Rnd + ilower)
Ito = Int((Iupper - ilower + 1) * Rnd + ilower)
ActivePresentation.Slides(ifrom).MoveTo (Ito)

Next i

Exit Sub

Err: MsgBox " Shuffle failed", vbCritical

End Sub

2

2 Answers

0
votes

Untested and swiped from another site but below is a snippet to randomize slides. As far as running at startup though, I don't have a code answer but what if you made a title slide with a begin game/study flashcards/(whatever yours is for) button that runs the macro and turn off advance slide on click?

Sub sort_rand()

Dim i As Integer
Dim myvalue As Integer
Dim islides As Integer
islides = ActivePresentation.Slides.Count
For i = 1 To ActivePresentation.Slides.Count
    myvalue = Int((i * Rnd) + 1)
    ActiveWindow.ViewType = ppViewSlideSorter
    ActivePresentation.Slides(myvalue).Select
    ActiveWindow.Selection.Cut
    ActivePresentation.Slides(islides - 1).Select
    ActiveWindow.View.Paste
Next

End Sub

0
votes

An Auto_Open subroutine will run when an add-in containing it loads but not when a presentation containing it opens.

If you can install an add-in on the user's system, the add-in could set an event trap for the Presentation Open event, examine the newly opened presentation for some feature (name, existence of known shapes on slide/master, tags) that identifies it as "your" presentation and if so, run your existing code.

A google search for "powerpoint events" (sans the quote marks) will point you at more about event handler code in vba