Results 1 to 20 of 56

Thread: How to scramble tables in word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    mana,

    Thanks for posting. It seems we both were initially duped thinks that the tables would have to be duplicated in some manner. Turns out not to be the case. This adaptation of your dictionary and random processes is much faster:

    Sub test5()
        Dim oDic As Object, oRanNumGen As Object
        Dim lngIndex As Long, lngRandom As Long
        Dim lngCount As Long
        Dim oRng As Range, oRng2 As Range
        Dim oTbls As Tables
        Set oTbls = ActiveDocument.Tables
        Set oDic = CreateObject("scripting.dictionary")
        Set oRanNumGen = CreateObject("system.random")
        Application.ScreenUpdating = False
        lngCount = oTbls.Count
        Do
             lngRandom = oRanNumGen.next_2(1, lngCount + 1)
             oDic(lngRandom) = Empty
             If oDic.Count = lngCount Then Exit Do
        Loop
        For lngIndex = 1 To oDic.Count
             Set oRng = oTbls(oDic.keys()(lngIndex - 1)).Range
             Set oRng2 = oTbls(lngIndex).Range
             If Not oRng = oRng2 Then
                 oRng2.Tables(1).Delete
                 oRng2.FormattedText = oRng.FormattedText
             End If
        Next
        lbl_Exit:
        Set oTbls = Nothing: Set oRng = Nothing: Set oRng2 = Nothing
        Set oDic = Nothing: Set oRanNumGen = Nothing
        Exit Sub
    End Sub
    Where can I read up about system.random? I found an article but it didn't include the next_2 method. Also, what does dic(n) = Empty really do?
    Last edited by Aussiebear; 01-20-2025 at 04:38 AM.
    Greg

    Visit my website: http://gregmaxey.com

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
  •