Thread: [Solved] table removal syntax
View Single Post
 
Old 01-23-2015, 03:49 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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:
your code works but it's deletes all tables accept the first one
Indeed it does, which is what I took your request to mean. However if you want every other table removed then using the similar syntax:

Code:
Sub Removetables()
Dim oTable As Table
Dim i As Integer
    i = 1
    For Each oTable In ActiveDocument.Tables
        If i Mod 2 = 1 Then oTable.Delete
        i = i + 1
    Next oTable
End Sub
This will remove table 1, table 3, table 5 etc
If you want to remove table 2, table 4, table 6 etc then change
Code:
If i Mod 2 = 1 Then oTable.Delete
to
Code:
If i Mod 2 = 0 Then oTable.Delete
__________________
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