PDA

View Full Version : Random SlideShow Powerpoint



kunguito
06-17-2007, 12:54 PM
Hi everyone,

First post here! I'll try to keep it clean! I promise!

I am trying write a macro that makes a random Slideshow out of a Presentation. Downloading an AddIn that does it is not an option (Specially if it's not freeware).

Here is the code I wrote.
What does it do?
0. There is an open presentation.
1. Build an array containing the ID's of the slides of the presentation.
2. Shuffle the array containing the ID's.
3. Create a NamedSideShow.
4. Run it.
5. Delete the NamedSlideShow ( I don't know if it really deletes it).

The problem is that even when it randomly Shuffles the array, the NamedSlideShow created seems to have the order of the slides of the presentation (Not Shuffled).

Any Idea of how to do that?



Sub RandomSlideShow()
Dim numSlides As Integer
Dim i As Integer
numSlides = ActivePresentation.Slides.Count 'Counts the number of Slides of the presentation
Dim qSlides() As Long 'Dynamically created
ReDim qSlides(1 To numSlides) As Long '
'Store the ID of every slide in qSlides
For i = 1 To numSlides
qSlides(i) = ActivePresentation.Slides.Item(i).SlideID
Next
ArrayShuffle (qSlides) 'Randomizes the positions of the slides ID.
With ActivePresentation.SlideShowSettings
.NamedSlideShows.Add "Show Random", qSlides
.RangeType = ppShowNamedSlideShow
.SlideShowName = "Show Random"
.AdvanceMode = ppSlideShowUseSlideTimings
.Run
.NamedSlideShows.Item("Show Random").Delete
End With
End Sub


Next Doubts:

In the future I would like to create some kind of keyboard event so that when a certain key was pressed the presentation would continue without the slide. Any Guideline/ Idea?

lion
06-17-2007, 02:45 PM
Hi
The following doesn't answer all your queries but it does shuffle slides and play them in the shuffled order! The number of 'shuffles' etc can be altered.


Sub RandomSlides()
Dim intSlideCount As Integer
Dim intRandomCut As Integer
Dim intRandomPaste As Integer
Dim intLoopCounter As Integer
'Count number of slides excluding the first two (don't want these shuffled)
intSlideCount = Application.ActivePresentation.Slides.Count
intSlideCount = intSlideCount - 2
' Initialize random-number generator.
Randomize
'Repeat the random change 10 times
For intLoopCounter = 0 To 10
' Generate random value between 3 and last slide.
intRandomCut = Int((intSlideCount * Rnd) + 3)
intRandomPaste = Int((intSlideCount * Rnd) + 3)
'Move a randomly chosen slide from 1 position to another
ActivePresentation.Slides(intRandomCut).MoveTo toPos:=intRandomPaste
Next
'Move to next slide
SlideShowWindows(Index:=1).View.Next
End Sub

You might be able to adapt this to fit your presentation :)

kunguito
06-17-2007, 02:52 PM
Thanks lion, but doesn't it alter the presentation?
I would like it to remain the same.

Anyway, I am curious to know what does this line mean

SlideShowWindows(Index:=1).View.Next

lion
06-17-2007, 03:11 PM
Yes it does alter the order of the presentation - this did not matter for my project - I just wanted the slides to be played in a different order each time I ran the presentation. If you need to keep the original order, the code won't help. :(

The last line just took me to the next slide - ignore it!