Consulting

Results 1 to 2 of 2

Thread: How to arrange tables in order as shown in VBA code. Hope everybody help please. Tks

  1. #1
    VBAX Regular
    Joined
    Jan 2021
    Posts
    8
    Location

    How to arrange tables in order as shown in VBA code. Hope everybody help please. Tks

    How to arrange the tables in the order shown in the picture using VBA code. Hope everybody help please. thanks
    Attached Images Attached Images

  2. #2
    The following should work

    Sub SortTables()
    'Graham Mayor - https://www.gmayor.com - Last updated - 23 Jun 2021 
    Dim oTable As Table
    Dim oRng As Range
    Dim i As Integer
        Set oRng = ActiveDocument.Range
        oRng.Select
        Selection.Sort ExcludeHeader:=False, _
                       FieldNumber:="Paragraphs", _
                       SortFieldType:=wdSortFieldAlphanumeric, _
                       SortOrder:=wdSortOrderAscending
        Set oTable = ActiveDocument.Tables(1)
        Set oRng = oTable.Range
        With oRng.Find
            .Text = "^p"
            .Replacement.Text = ""
            .Execute Replace:=wdReplaceAll
        End With
        For i = oTable.Rows.Count - 1 To 2 Step -2
            oTable.Rows(i).Select
            Selection.SplitTable
        Next i
        Set oTable = Nothing
        Set oRng = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •