Hello all,
I'm stuck again. I was helped in identifying the tables that have 2 columns,
but unfortunately, there are some I don't want to delete. However, those that
are to be deleted have the text "Actio" in the second column of the first
row. I hav tried a few options, but now I get a type mismatch on the line -
Set myrange = ActiveDocument.Tables(1).Cell(2, 1).Range.Text
The full coide is:
Sub delTables()
Dim nCounter As Long
Dim nNumTables As Long
Dim oTable As Word.Table
Dim c As Word.Cell
Dim myrange As Range
'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)
Set myrange = ActiveDocument.Tables(1).Cell(2, 1).Range.Text
'With oTable
' .Columns.Count = 2
' .Cell(2
'If the table has 2 columns...
If oTable.Columns.Count = 2 And myrange.Text = "Action" Then
'If oTable.Cell(1, 2).Text = "Action" Then
'...delete it
oTable.Delete
End If
End If
Next nCounter
End Sub
Any suggestions on where I am going wrong?
Thanks

Signature
Brian McCaffery
Doug Robbins - Word MVP - 08 Nov 2007 10:20 GMT
By including the .Text at the end of the Set command, you are trying to
assign a string to a range variable. Delete the .Text from that command and
the use:
myrange.End = myrange.End -1 ' to remove the end of cell character from the
range
then
If myrange.Text = "Action" then
myrange.Tables(1).Delete
End If

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Hello all,
>
[quoted text clipped - 50 lines]
>
> Thanks
Russ - 08 Nov 2007 10:33 GMT
Bryan,
Try This:
Sub delTables()
Dim oTable As Word.Table
For each oTable in ActiveDocument.Tables
If oTable.Columns.Count = 2 And oTable.Cell(2,1).Range.Text = "Action" Then
oTable.Delete
End If
Next oTable
End Sub
I think with counters, you should count backwards, but I don't think it is
necessary with for 'each loops' and 'for each' loops are faster than counter
loops.
> Hello all,
>
[quoted text clipped - 49 lines]
>
> Thanks

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID