Thread: [Solved] table removal syntax
View Single Post
 
Old 01-22-2015, 11:32 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
For i = ActiveDocument.Tables.Count To 2 Step -2
Unless you want to retain every other table you need Step -1
This will leave the first table.

You could also modify the original code method to introduce a counter e.g.

Code:
Sub Removetables()
Dim oTable As Table
Dim i As Integer
    i = 1
    For Each oTable In ActiveDocument.Tables
        If i > 1 Then oTable.Delete
        i = i + 1
    Next oTable
End Sub
Both methods are likely to leave empty paragraphs.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote