PDA

View Full Version : Selecting all Single row tables word 2010



n35
05-21-2012, 03:46 AM
hello

So using Kutools, (google it if you need to know what it is -Sorry unable to make links because I just registered. ) I can select all single row tables.

However I'd lke to be able to do it via VBA, as that will allow me to apply formatting directly via macros.

However I cant quite seem to figure out how to select all tables with a varying number of rows.

Selecting all tables, is not good enough, as that would apply the same formatting to tables with 10 rows as those with 1 row.

IS anyone able to offer some example code which will allow me to select all tables in a word document which has only 1 row.?

Regards
N35

Frosty
05-21-2012, 08:50 AM
Something like this?

Sub Demo
dim oTable as Table

For Each oTable In ActiveDocument.Tables
If oTable.Rows.Count = 1 Then
'Apply your table format here
End If
Next
End Sub

I'm not sure if, in 2010, you can non-contiguously select tables via VBA... but the above code would loop through all the tables in the document, and only "do something" on tables with a single Row.

All the usual caveat emptor disclaimers apply here, as if you have ever vertically merged cells in any of these tables, you may appear to have a single row table, but in fact it will look to VBA as a multi-row table.

But that's a simple structure to allow you to filter out multi-row tables.

n35
05-23-2012, 05:24 AM
Thanks, works like a charm :)