Log in

View Full Version : Solved: Find and delete ALL one row (header only) tables



Jinky Julie
04-07-2009, 06:18 AM
Hi again all,


How do I search through an entire document for all tables containing one row (i.e. the header) and delete them??

I cannot seem to find what apparently is an answer to that simple question...

I am still new to VBA.... I am sure I am close... but I look to you...

Thanks for your time and anticipated rescue...

Julie

fumei
04-07-2009, 08:17 AM
The fact that it is a header row is not relevant..if I understand you correctly.

You are asking: how do I delete all tables with one row?

This is very easy. You go through all the tables in the document, checking to see if it has one row. If it does, delete the table.

Option Explicit

Sub DeleteOneRowTables()
Dim oTable As Table
For Each oTable In ActiveDocument.Tables
If oTable.Rows.Count = 1 Then
oTable.Delete
End If
Next
End Sub
Demo document attached. Click "Delete One Row Tables" on the top toolbar.

Jinky Julie
04-07-2009, 08:30 AM
Worked like a charm Fumei!!!

I knew it was easy... and I was close... just getting used to the DOM, etc...

Thanks bunches....:bow:

Julie

fumei
04-07-2009, 09:01 AM
You are welcome.