Consulting

Results 1 to 18 of 18

Thread: How to Randomize Only VISIBLE Slides, Not Hidden Slides??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,718
    Location
    Try the attachment - barebones and needs some prettying-up


    Option Explicit
    
    
    Dim arySlides() As Long, cntSlides As Long
    Dim aryRandom() As Double
    Dim oPres As Presentation
    
    
    Sub PickSlide(oShapeIn As Shape)
    
    
        Call SetupRandomVisibleSlides
        
        Select Case oShapeIn.Name
            Case "Class 1"
                Call GotoSlide(1)
            Case "Class 2"
                Call GotoSlide(2)
        End Select
    End Sub
    
    
    Private Sub GotoSlide(ClassNum As Double)
        Dim i As Long
        
        For i = LBound(aryRandom) To UBound(aryRandom)
            If aryRandom(i) = ClassNum Then
                SlideShowWindows(1).View.GotoSlide arySlides(i + 1)
                Exit Sub
            End If
        Next i
    
    
    End Sub
    
    
    
    
    Private Sub SetupRandomVisibleSlides()
        Dim oSlide As Slide, oShape As Shape
        Dim i As Long, j As Long
        Dim HoldRnd As Double, HoldSlide As Long
        Dim cntGroup As Double
        
        Randomize
        
        Set oPres = ActivePresentation
        
        cntSlides = 0
        cntGroup = 0#
        
        For Each oSlide In oPres.Slides
            For Each oShape In oSlide.Shapes
                If oShape.Type = msoPlaceholder Then
                    If oShape.PlaceholderFormat.Type = ppPlaceholderTitle Then
                        If oShape.TextFrame.HasText Then
                            If LCase(oShape.TextFrame.TextRange.Text) Like "class*" Then
                                cntGroup = cntGroup + 1
                                cntSlides = cntSlides + 1
                                ReDim Preserve arySlides(1 To cntSlides)
                                arySlides(cntSlides) = oSlide.SlideNumber
                                ReDim Preserve aryRandom(1 To cntSlides)
                                aryRandom(cntSlides) = cntGroup
                                GoTo NextSlide
                            End If
                        End If
                    End If
                End If
            Next oShape
            
            If cntGroup = 0 Then GoTo NextSlide
        
            If Not oSlide.SlideShowTransition.Hidden Then
                cntSlides = cntSlides + 1
                ReDim Preserve arySlides(1 To cntSlides)
                arySlides(cntSlides) = oSlide.SlideNumber
                ReDim Preserve aryRandom(1 To cntSlides)
                aryRandom(cntSlides) = cntGroup + Rnd
            End If
            
    NextSlide:
        Next oSlide
    
    
    
    
        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
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •