mortiferum
05-31-2016, 07:27 AM
Hi, Im very new to VBA
Imagine a PPT with 6 slides in total; slides 1,2,3,4,5 and 6
Slides 1 & 6 are in a fixed position they should always been seen first and last respectively.
I would like to use VBA to randomonly select and show 2 slides out of the 4 remaining slides (2,3,4 & 5).
One way I assume (let me know if theres another) that this can be achieved is to firstly randomise / shuffle the slide order for slides (2,3,4 & 5) and then only display the first two slides from this selection?
I've used the following VBA code that I found on the Internet to 'shuffle' slides 2 to 5 but I cant find out how to only then select the first two slides from this selection?
Sub shufflerange()
Dim Iupper As Integer
Dim Ilower As Integer
Dim Ifrom As Integer
Dim Ito As Integer
Dim i As Integer
Iupper = 5
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 "Your choices are out of range", vbCritical
End Sub
After using this code (as an example) I 'could' end up with the slides in the following order 1,3,2,5,4 & 6
Is there a way to VBA code so I end up with slides 1,3,2 & 6 being viewed in the slideshow (without slides 5 & 4 being permently deleted).
If I ran / opened the PPt a 2nd time I could end up with slides 1,5,2 & 6 in the slideshow.
Many thanks
Morty
Imagine a PPT with 6 slides in total; slides 1,2,3,4,5 and 6
Slides 1 & 6 are in a fixed position they should always been seen first and last respectively.
I would like to use VBA to randomonly select and show 2 slides out of the 4 remaining slides (2,3,4 & 5).
One way I assume (let me know if theres another) that this can be achieved is to firstly randomise / shuffle the slide order for slides (2,3,4 & 5) and then only display the first two slides from this selection?
I've used the following VBA code that I found on the Internet to 'shuffle' slides 2 to 5 but I cant find out how to only then select the first two slides from this selection?
Sub shufflerange()
Dim Iupper As Integer
Dim Ilower As Integer
Dim Ifrom As Integer
Dim Ito As Integer
Dim i As Integer
Iupper = 5
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 "Your choices are out of range", vbCritical
End Sub
After using this code (as an example) I 'could' end up with the slides in the following order 1,3,2,5,4 & 6
Is there a way to VBA code so I end up with slides 1,3,2 & 6 being viewed in the slideshow (without slides 5 & 4 being permently deleted).
If I ran / opened the PPt a 2nd time I could end up with slides 1,5,2 & 6 in the slideshow.
Many thanks
Morty