1 Attachment(s)
How to Randomize Only VISIBLE Slides, Not Hidden Slides??
Hello all, I'm trying to make my code only randomize non-hidden slides. I'm a noobie to VBA. I've just tried to figure it out logically, but I'm afraid I lack fundamental coding knowledge to solve this problem.
There are 6 slides and the code will randomize them successfully if I leave out the If statement about "SlideShowTransition.Hidden = False" - So therein lies the problem...
Code:
Sub RandomVisibleSlides ()
FirstSlide = 1
LastSlide = 6
RSN = SlideIndex
Randomize
'generate random number for Index
GRN:
RSN = Int((LastSlide - FirstSlide + 1) * Rnd + FirstSlide)
If RSN = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex Then
If ActivePresentation.Slides(RSN).SlideShowTransition.Hidden = False Then GoTo GRN
ActivePresentation.SlideShowWindow.View.GotoSlide (RSN)
End Sub
My experiment PowerPoint is attached.
What am I doing wrong?
1 Attachment(s)
Revised PPT to more accurately represent my goal
Good suggestion. I tried to revise the PPT I originally posted to give a more accurate representation of my goal.
The code should just GoTo /hyperlink to a student's slide, but not change the order of the slides.
They need to stay in the same order index day after day.
Some students will be absent quite often, and on those days I will hide their slides.
My problem is that my current Randomizer still jumps to 'hidden' slides.
Thank you for your time-
VBA code randomvisibleslide
Quote:
Originally Posted by
Paul_Hossler
Try this
It uses SlideID and a simple bubble sort
Hidden slides are pushed to the end
Code:
Option Explicit
Sub RandomVisibleSlides()
Dim arySlides() As Long, cntSlides As Long
Dim oSlide As Slide, oPres As Presentation
Dim aryRandom() As Double
Dim i As Long, j As Long
Dim HoldRnd As Double, HoldSlide As Long
Randomize
Set oPres = ActivePresentation
cntSlides = 0
For Each oSlide In oPres.Slides
If Not oSlide.SlideShowTransition.Hidden Then
cntSlides = cntSlides + 1
ReDim Preserve arySlides(1 To cntSlides)
arySlides(cntSlides) = oSlide.SlideID
ReDim Preserve aryRandom(1 To cntSlides)
aryRandom(cntSlides) = Rnd
End If
Next
For i = LBound(arySlides) To UBound(arySlides) - 1
For j = i + 1 To UBound(arySlides)
If aryRandom(i) > aryRandom(j) Then
HoldRnd = aryRandom(i)
aryRandom(i) = aryRandom(j)
aryRandom(j) = HoldRnd
HoldSlide = arySlides(i)
arySlides(i) = arySlides(j)
arySlides(j) = HoldSlide
End If
Next j
Next i
For i = LBound(arySlides) To UBound(arySlides)
oPres.Slides.FindBySlideID(arySlides(i)).MoveTo i
Next i
End Sub
This code works perfect, but is works for all sheets in my slideshow.
Is it also posible to this with a small selections of sheets, so sheet 19 till 23?
Greetz Tyas