How to arrange the tables in the order shown in the picture using VBA code. Hope everybody help please. thanks
How to arrange the tables in the order shown in the picture using VBA code. Hope everybody help please. thanks
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