List Randomizer Macro for Word 2010

incurablegeek

New Member
Joined
Apr 5, 2014
Messages
1
Way back with Word '97 one of my students wrote a convenient macro for randomizing lists of words. Briefly, the list was highlighted and the Macro button (or keystrokes) pushed - and the list was nicely randomized.

I do not have this Macro anymore and need a similar one for Office 2010 32 bit (MS Word only).

Note: I am well aware of online randomizers as well as using Excel to randomize a list. However, I wish to eliminate time/energy wasted steps and randomize word lists within Word 2010 itself.

Any suggestions?

Please forgive me if this question is not appropriate for this thread. :)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
The code below separates the selection by paragraphs (or line breaks). Then, it randomizes the paragraphs and, finally, replaces the selection with the randomized content. Obviously, the paragraphs may be single words, phrases, or long, drawn out sentences.

Select the words / phrases you want to randomize, then run RandomizeSelection.

The code borrows heavily from the code at Random Selection

Code:
Option Explicit

Sub Swap(ByRef Arr As Variant, ByVal I As Long, ByVal j As Long)
        Dim temp As Variant
        temp = Arr(I): Arr(I) = Arr(j): Arr(j) = temp
        End Sub

Sub RandomSelect(ByRef Arr As Variant, ByVal N As Long)
        'Returns N elements out of m, the size of Arr. _
         The lower N elements of the array will contain the _
         unique random values
    Dim I As Long, thisIdx As Long
    'Need edits to ensure Arr is an acceptable data type. _
     Similarly, validate n
    For I = 1 To N
        thisIdx = LBound(Arr) + (I - 1) _
            + Int((UBound(Arr) - (LBound(Arr) + (I - 1)) + 1) * Rnd())
        Swap Arr, LBound(Arr) + (I - 1), thisIdx
        Next I
    End Sub

Sub RandomizeSelection()
    Dim Sel: Sel = Split(Replace(Selection, Chr(11), Chr(13)), Chr(13))
    If Sel(UBound(Sel)) = "" Then ReDim Preserve Sel(UBound(Sel) - 1)
    Randomize
    RandomSelect Sel, UBound(Sel) - LBound(Sel) + 1
    Selection = Join(Sel, Chr(13))
    Stop
    End Sub

Way back with Word '97 one of my students wrote a convenient macro for randomizing lists of words. Briefly, the list was highlighted and the Macro button (or keystrokes) pushed - and the list was nicely randomized.

I do not have this Macro anymore and need a similar one for Office 2010 32 bit (MS Word only).

Note: I am well aware of online randomizers as well as using Excel to randomize a list. However, I wish to eliminate time/energy wasted steps and randomize word lists within Word 2010 itself.

Any suggestions?

Please forgive me if this question is not appropriate for this thread. :)
 
Upvote 0

Forum statistics

Threads
1,216,122
Messages
6,128,964
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top