Randomize pages in word

T

Tripeptide

I am a student who has approximately 1500 3x5 inch notecards in word. All of
the questions are on odd pages and the answers are on even pages. It is VERY
time consuming to print them for review.

Is there a way to randomize pages in word such that the odd number page will
always be followed by the next even number page so it's like shuffling a deck
of cards?

Any help would be greatly appreciated.
 
H

Helmut Weber

Hi,

it is not about just generating an odd random number,
but about avoiding getting the same number again.
One method would be, to create an array form 1 to
the number of pages in your doc and shuffle the
values in the array. That is the more difficult part,
from which I took code posted once by Rick Rothstein.

Here we go:
' -----------------------------------------------------------------
Sub Test863q()
Dim x As Long ' a counter
Dim r As Long ' result from messagebox
Dim pg As Long ' a pagenumber
Dim pa As Long ' pages all
pa = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ReDim arr(1 To pa)
For x = 1 To pa
arr(x) = x
Next
arr = RandomizeArray(arr)
For x = 1 To pa
r = MsgBox("Give me a card", vbOKCancel)
If r = 1 Then
pg = arr(x)
If pg Mod 2 = 0 Then
pg = pg - 1
ActiveDocument.PrintOut _
Range:=wdPrintFromTo, _
from:=CStr(pg), to:=CStr(pg + 1)
End If
End If
If r = 2 Then Exit Sub
Next

End Sub
' --------------------------------------------------------------------
Function RandomizeArray(ArrayIn As Variant) As Variant
' Rick Rothstein (MVP VP)
Dim x As Long
Dim RandomIndex As Long
Dim TempElement As Variant
Static RanBefore As Boolean
If Not RanBefore Then
RanBefore = True
Randomize
End If
'Stop
If VarType(ArrayIn) >= vbArray Then
For x = UBound(ArrayIn) To LBound(ArrayIn) Step -1
RandomIndex = Int((x - LBound(ArrayIn) + 1) * _
Rnd + LBound(ArrayIn))
TempElement = ArrayIn(RandomIndex)
ArrayIn(RandomIndex) = ArrayIn(x)
ArrayIn(x) = TempElement
Next
Else
'The passed argument was not an array
'Put error handler here, such as . . .
Beep
End If
'For X = 1 To 38
' MsgBox ArrayIn(X)
'Next
RandomizeArray = ArrayIn
End Function

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top