Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2015, 10:40 PM
PolarisTLX PolarisTLX is offline Macros to select random odd numbered slide Windows 7 64bit Macros to select random odd numbered slide Office 2007
Novice
Macros to select random odd numbered slide
 
Join Date: Jan 2015
Posts: 1
PolarisTLX is on a distinguished road
Question Macros to select random odd numbered slide


Trying to create random flash cards using power point.

I think I almost have the code right. I only need a slight modification to it.


Slide 1 is question. Slide 2 is Answer. All odd numbered slides are questions and their subsequent answer is the next slide.

After seeing an answer (even numbered slide) I would place a link that runs the macros which picks the next random question (odd numbered slide).

So I would just need a macros that chooses another random odd numbered slide. That number should also be less then the total number of slides.



I think I almost have it working from an example I found that is loosely similar but it doesn't quite work perfectly. This is what I have so far:

Dim visited() As Boolean
Dim numSlides As Long
Dim numRead As Integer
Dim numWanted As Integer
Sub Initialize()
Randomize
numWanted = 5
numRead = 0
numSlides = ActivePresentation.Slides.Count
ReDim visited(numSlides)
For i = 2 To numSlides - 1
visited(i) = False
Next i
End Sub
Sub RandomNext()
Dim nextSlide As Long

If numRead >= numWanted Or numRead >= numSlides - 2 Then
ActivePresentation.SlideShowWindow.View.Last
Else
nextSlide = Int((numSlides - 2) * Rnd + 2)
While visited(nextSlide) = True
nextSlide = Int((numSlides - 2) * Rnd + 2)
Wend
ActivePresentation.SlideShowWindow.View.GotoSlide nextSlide
End If
End Sub


Anyone know what I need to change or have a better code for this?

Thank you very much.
Reply With Quote
  #2  
Old 01-08-2015, 02:26 AM
JohnWilson JohnWilson is offline Macros to select random odd numbered slide Windows 7 64bit Macros to select random odd numbered slide Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

Maybe something based on:

Sub getNext()
Dim lngCount As Long
Dim lngOddslides As Long
Static rayOdd() As Long
Dim L As Long
Dim x As Integer
Dim nextSld As Long
lngCount = ActivePresentation.Slides.Count
lngOddslides = lngCount \ 2 + lngCount Mod 2
On Error Resume Next
Err.Clear
If UBound(rayOdd) < 1 Or rayOdd(1) = 0 Then
ReDim rayOdd(1 To lngOddslides)
For L = 1 To lngCount Step 2
x = x + 1
rayOdd(x) = L
Next L
End If
nextSld = Int(Rnd * (UBound(rayOdd))) + 1
SlideShowWindows(1).View.GotoSlide rayOdd(nextSld)
rayOdd(nextSld) = rayOdd(UBound(rayOdd))
If UBound(rayOdd) > 1 Then
ReDim Preserve rayOdd(1 To UBound(rayOdd) - 1)
Else: ReDim rayOdd(1 To 1)
End If
End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
Reply

Tags
macros

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Mixing Numbered Headings with Numbered List Tess0 Word 11 07-15-2014 05:25 AM
Macros to select random odd numbered slide Lyric slide show - using a variable to pull text from next slide elfman12 PowerPoint 3 03-08-2013 12:27 AM
Macros to select random odd numbered slide Text typed on slide x ports to slide y automatically? Thinker PowerPoint 5 07-26-2012 11:59 PM
Macros to select random odd numbered slide Create PPT slide presentation with Excel data. Chart is displayed off the slide. eratem PowerPoint 4 02-29-2012 09:44 AM
PP 07 Random Chart Dissappearing in Slide Show DKY PowerPoint 0 11-02-2011 04:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft