Word VBA: randomize paragraphs

Sub ran_para()
    n = ActiveDocument.Paragraphs.Count
    ReDim a(1 To 2, 1 To n)
    Randomize
    For i = 1 To n
        a(1, i) = Rnd
        a(2, i) = i
    Next
    For i = 1 To n - 1
        For j = i + 1 To n
            If a(1, j) > a(1, i) Then
                t = a(2, i)
                a(2, i) = a(2, j)
                a(2, j) = t
            End If
        Next
    Next
    'Documents.Add
    For i = 1 To n
        Set p = ActiveDocument.Paragraphs.Add
        p.Range.Text = ActiveDocument.Paragraphs(a(2, i)).Range.Text
    Next
End Sub
Share

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)