Hi Sam,
Let's say the "item info" table has a default number of rows (5) , as does
the "comments" table (4). That adds up to 9 rows, which is how many rows you
need to keep.
So, if you add 2 rows to the "item info" table, it's now got 7 rows and the
"comments" table needs to have 9-7=2 rows.
Then, if you delete 3 rows from the "item info" table, it's now got 4 rows
and the "comments" table needs to have 9-4=5 rows.
Assuming you always want to programmatically add/delete the last row(s) in
the "comments" table, and your tables are bookmarked "ItemInfo" and
"Comments", respectively, your code would go something like:
Sub MaintainTables()
Dim T1Rows As Integer
Dim T2Rows As Integer
Dim RowCount As Integer
Dim DefRows As Integer
DefRows = 9
With ActiveDocument
T1Rows = .Bookmarks("ItemInfo").Range.Tables(1).Rows.Count
T2Rows = .Bookmarks("Comments").Range.Tables(1).Rows.Count
RowCount = T1Rows + T2Rows
With .Bookmarks("Comments").Range.Tables(1)
If RowCount < DefRows Then
.Rows(T2Rows).Select
Selection.InsertRowsBelow DefRows - RowCount
ElseIf RowCount > ReqCount Then
For i = RowCount - T1Rows To DefRows - T1Rows + 1 Step -1
.Rows(i).Delete
Next
End If
End With
End With
End Sub
To work with a different number of rows, change the '9' in 'DefRows = 9' to
the required number.
Cheers
> Hi,
>
[quoted text clipped - 11 lines]
>
> Sam
sam - 06 May 2006 13:54 GMT
HI, Macropod
Thank you!!! perfect!
I encountered a new problem right now. In this method, I think we
defaulted that the size of each row in both table is the same. However,
in my case, it is not like this. I only have one row in the table
"Comments". So the size of this specific row is variable. Here is my
idea, I want to set the ending point of the table "comments" in a
specific place of that page, like "row 21" of that page. Is it possible
to implement this using VBA? Do you have some good ideas? Thank you in
advance!!!
Best Regards
Sam
As the size of specific row in table is variable, for example, if I
deleted two rows in table "item info", which
macropod - 07 May 2006 06:58 GMT
Hi Sam,
If you want to adjust the height of your comment row, then you'll need to
set the height of the rows in the "item info" table to 'exact'. That's
because Word doesn't hold a meaningful value for row heights that are set to
autosize.
Other than that, the logic is pretty much the same but, instead of counting
rows, you'll be measuring row heights and adjusting the row height in your
"comments" table to suit.
Cheers
sam - 07 May 2006 10:16 GMT
HI,Macropod
As my understanding, your idea is to calculate the rows height that
added or deleted in table "item info", insteand of counting rows. Did
you know the clause in VBA to enlarge the height of only row in table
"comments"? Could you give me some hint?Thank you!
Best Regards
Sam
macropod - 07 May 2006 11:43 GMT
Hi Sam,
You don't need code to increase/decrease the row height as such - all you
need to do is to calculate what it should be and set it to that. Hint:
Tables(1).Rows(1).Height = ???
Cheers
> HI,Macropod
>
[quoted text clipped - 6 lines]
>
> Sam