Hi all,
I am trying to find all tables containing only 2 columns in a document,
select them, and then delete. Getting no where fast. Any suggestions
gratefully received.
Sub delTables()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
With ActiveDocument.Tables
If NumColumns = 2 Then
'If ActiveDocument.Tables.Count >= 1 Then
ActiveDocument.Tables.Select
Selection.Delete
End If
End With
Next oTbl
End Sub
Thanks,

Signature
Brian McCaffery
Shauna Kelly - 22 Oct 2007 08:23 GMT
Hi Brian
Try this....
Sub delTables()
Dim nCounter As Long
Dim nNumTables As Long
Dim oTable As Word.Table
'Find out how many tables there are
nNumTables = ActiveDocument.Tables.Count
'Start at the last table, and work backwards
'through the tables in the document.
'We do this because we are deleting tables,
'and the index would go awry as we cycled
'through them.
For nCounter = nNumTables To 1 Step -1
'Get a reference to this table
Set oTable = ActiveDocument.Tables(nCounter)
'If the table has 2 columns...
If oTable.Columns.Count = 2 Then
'...delete it
oTable.Delete
End If
Next nCounter
End Sub
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
> Hi all,
>
[quoted text clipped - 18 lines]
>
> Thanks,
Brian - 22 Oct 2007 08:41 GMT
Thank you Shauna.
It worked a treat. One more question if its not too cheeky, Would it be
possible to not only identify the table to delete by the number of columns,
but also by the word Action in the second column of the table header row? At
the moment, I copy the relevant section to a new document, tidy the section,
then copy it back.
I am stripping out screen captures and step tables from large documents cica
300 pages to reduce to 30 pages. SOPs.
Thanks,

Signature
Brian McCaffery
> Hi Brian
>
[quoted text clipped - 56 lines]
> >
> > Thanks,
Russ - 22 Oct 2007 08:49 GMT
This is from VBA Help for the columns collection:
MsgBox ActiveDocument.Tables(1).Columns.Count
Or in your case
Sub delTables()
Dim oTbl As Table
'If ActiveDocument.Tables.Count >= 1 Then
For Each oTbl In ActiveDocument.Tables
If oTbl.Columns.Count = 2 then
oTbl.Delete
' or oTbl.Range.Delete
End If
Next oTbl
'End If
End Sub
> Hi all,
>
[quoted text clipped - 18 lines]
>
> Thanks,

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID