#1
|
|||
|
|||
table removal syntax
Hello everyone
I have a lot of tables in word document and I want to delete one table and leave one .. until the end of document I found in internet this code - to remove all tables - but still have a syntax error ... -------------------- Sub Removetables () Dim oTable As Table Each oTable In ActiveDocument.Tables oTable.Delete Next oTable End Sub ----------------- Can someone help me to write code to delete one table and leave one ... Thanks for everyone |
#2
|
||||
|
||||
You need to work backwards since the act of deleting a table reduces the number of tables in the document.
Sub RemoveTables2() Dim i As Integer For i = ActiveDocument.Tables.Count To 2 Step -2 ActiveDocument.Tables(i).Delete Next i End Sub PS. The code you posted is erroring because you are missing the word 'For' in the front of the 'Each ...' line |
#3
|
||||
|
||||
Quote:
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
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
Best Answer
Quote:
Quote:
Thanks for all once again May God reward you |
#5
|
||||
|
||||
Quote:
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 If you want to remove table 2, table 4, table 6 etc then change Code:
If i Mod 2 = 1 Then oTable.Delete 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 |
#6
|
|||
|
|||
Fantastic Answer
Quote:
Aha it's okay , anyway , Thank you for trying to lend a hand Quote:
Quote:
I Appreciating your consideration and cooperation |
Tags |
help please, tables, word vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Strange Characters Removal | OceansBlue | Word | 2 | 04-03-2013 10:01 AM |
Please help with header and footer removal | pwangdel | Word | 3 | 11-03-2011 06:10 AM |
Field removal from template | Phelony | Word | 1 | 10-18-2011 03:28 AM |
background graphic removal | taffyevo | PowerPoint | 0 | 08-16-2011 06:36 AM |
Office 2007 removal and re-installation of previous version | Buckeyegator | Office | 1 | 03-25-2010 09:15 PM |