Same activity within all tables

S

stevewy

I have some addresses and contact details which have been churned out
by a database program, and I need to put them into a mail-mergable
format. It was originally extracted as RTF, but now it is in Word, I
find that each record is in its own little table, along with some
unwanted details.

I am trying to write a short macro that would go through each table in
the document in turn, and if it detects there are more than seven rows
in the table (not all the records are the same length), it will delete
row 7 of the table, then move on to the next table.

I have a basic structure for doing things to each table in a document:

Sub Table_Stuff()
Dim t As Table
For Each t In ActiveDocument.Tables
With t
[stuff to do in the table]
End With
Next
End Sub

.... but I cannot get the macro to delete row 7. Now, since not all
tables have seven rows, I first need to ascertain this by using, I
presume, Selection.Information(wdMaximumNumberOfRows). However, I
can't think of how to adapt this command for use in this macro.

I tried:

t.Information(wdMaximumNumberOfRows)

but that doesn't work.

Can anyone give me any suggestions?

Thanks so much.

Steve Wylie
Kent, England
 
M

macropod

Hi Steve,

Assuming you want to delete all rows beyond the 6th, try:

Sub TrimTables()
Dim oTbl As Table
Dim i As Integer
For Each oTbl In ActiveDocument.Tables
If oTbl.Rows.Count > 6 Then
For i = oTbl.Rows.Count To 7 Step -1
oTbl.Rows(i).Delete
Next
End If
Next
End Sub

Otherwise, if it's just the 7th row:

Sub TrimTables()
Dim oTbl As Table
Dim i As Integer
For Each oTbl In ActiveDocument.Tables
If oTbl.Rows.Count > 6 Then
oTbl.Rows(7).Delete
End If
Next
End Sub

Cheers
 
S

stevewy

Ah! Thanks for that - obviously I'd been barking up the wrong tree
with Selection.Information(wdMaximumNumberOfRows). I will keep hold
of your response as well, and hopefully it will come in useful if I
have any similar operations to do in the future.

Thanks again.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top