Consulting

Results 1 to 4 of 4

Thread: List Randomizer Macro for Word 2010

  1. #1

    Question List Randomizer Macro for Word 2010

    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?

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    @ All: Cross-posted at: http://www.msofficeforums.com/word-v...html#post62455
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Last edited by SamT; 04-28-2014 at 12:47 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    ARMaterials


    What I did use and what worked nicely I received from Greg Maxey. As follows:
    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim lngIndex As Long
    Dim arrWords() As String
    Dim arrRandom
      arrWords = Split(Left(Selection.Range.Text, Len(Selection.Range.Text) - 1), vbCr)
      arrRandom = RandomizeArray(arrWords)
      Selection.Delete
      For lngIndex = 0 To UBound(arrRandom)
        Selection.Range.Text = Selection.Range.Text & arrRandom(lngIndex) & vbCr
      Next lngIndex
    End Sub
    Function RandomizeArray(arrInput() As String) As Variant
    Dim lngIndex As Long
    Dim varTemp As Variant
    Dim lngRandom As Long
    Dim varRandomized As Variant
      
      Randomize
      ReDim varRandomized(LBound(arrInput) To UBound(arrInput))
      For lngIndex = LBound(arrInput) To UBound(arrInput)
        varRandomized(lngIndex) = arrInput(lngIndex)
      Next lngIndex
      For lngIndex = LBound(arrInput) To UBound(arrInput)
        lngRandom = CLng(((UBound(varRandomized) - lngIndex) * Rnd) + lngIndex)
        varTemp = varRandomized(lngIndex)
        varRandomized(lngIndex) = varRandomized(lngRandom)
        varRandomized(lngRandom) = varTemp
      Next lngIndex
      RandomizeArray = varRandomized
    End Function
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    snb
    This is what I posted:
    Sub M_randomise_words_snb() 
        Randomize 
         
        sn = Split(Trim(Replace(ActiveDocument.Content, vbCr, " "))) 
        sp = sn 
         
        For j = 0 To UBound(sp) - 1 
            sp(j) = sn(Rnd * (UBound(sn))) 
            sn = Split(Trim(Replace(Join(sn) & " ", sp(j) & " ", "", , 1))) 
        Next 
        sp(j) = sn(0) 
         
        Documents.Add.Content = Join(sp, vbCr) 
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

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
  •