B
Brian
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
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