Add row to the end of a table 
Author Message
 Add row to the end of a table

Hi All,

I'm having a problem adding a new row to the end of a table (always the last
one) in my Word document.  A snippet of the code I am using is as follows:

    With oWord

        Set oTable = .ActiveDocument.Tables(.ActiveDocument.Tables.Count)
        Set oRow = oTable.Rows.Add(oTable.Rows(1))

When I run this code I get the error "Cannot access individual rows in this
collection because the table has vertically merged cells.", because there
are some cells merged together, although not the last row (row 4) which is
how I want the new row formatted

I then tried adding a new table at the end of the document, right underneath
the existing one, but this seems to join the two tables together and when I
try to set the width of a cell, it changes the widths of the cells above!
The code I use for this is below:

    With oWord

        Set oRange = .ActiveDocument.Range
        oRange.Collapse wdCollapseEnd

        Set oTable = .ActiveDocument.Tables.Add(Range:=oRange, NumRows:=1,
NumColumns:=11)

Does anyone know what I am doing wrong, or have another idea about adding a
row to the end of a table?

TIA,

Steve.



Sat, 12 Feb 2005 22:18:28 GMT  
 Add row to the end of a table
In the code i use, i just say: oTable.Rows.Add
I dont' have any parenthesis after the function call.  

Quote:
>-----Original Message-----
>Hi All,

>I'm having a problem adding a new row to the end of a

table (always the last
Quote:
>one) in my Word document.  A snippet of the code I am

using is as follows:
Quote:

>    With oWord

>        Set oTable = .ActiveDocument.Tables

(.ActiveDocument.Tables.Count)
Quote:
>        Set oRow = oTable.Rows.Add(oTable.Rows(1))

>When I run this code I get the error "Cannot access

individual rows in this
Quote:
>collection because the table has vertically merged

cells.", because there
Quote:
>are some cells merged together, although not the last row
(row 4) which is
>how I want the new row formatted

>I then tried adding a new table at the end of the

document, right underneath
Quote:
>the existing one, but this seems to join the two tables
together and when I
>try to set the width of a cell, it changes the widths of
the cells above!
>The code I use for this is below:

>    With oWord

>        Set oRange = .ActiveDocument.Range
>        oRange.Collapse wdCollapseEnd

>        Set oTable = .ActiveDocument.Tables.Add

(Range:=oRange, NumRows:=1,
Quote:
>NumColumns:=11)

>Does anyone know what I am doing wrong, or have another
idea about adding a
>row to the end of a table?

>TIA,

>Steve.

>.



Sat, 12 Feb 2005 22:28:04 GMT  
 Add row to the end of a table
Hi, Steve,

As Jason says, omit the parameter from the .Add method. If you look at
the Help topic for the .Add, you'll see that the parameter represents
the row that should appear *after* the new row. If there wasn't any
merged cell and your code succeeded, you would have gotten your new row
at the top of the table, not the bottom. Omitting the parameter causes
the new row to go at the end of the table where you want it.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

Quote:

> In the code i use, i just say: oTable.Rows.Add
> I dont' have any parenthesis after the function call.

>> -----Original Message-----
>> Hi All,

>> I'm having a problem adding a new row to the end of a table (always
>> the last one) in my Word document.  A snippet of the code I am using
>> is as follows:

>>    With oWord

>>        Set oTable = .ActiveDocument.Tables
>>        (.ActiveDocument.Tables.Count) Set oRow =
>> oTable.Rows.Add(oTable.Rows(1))

>> When I run this code I get the error "Cannot access individual rows
>> in this collection because the table has vertically merged cells.",
>> because there are some cells merged together, although not the last
>> row (row 4) which is how I want the new row formatted



Sun, 13 Feb 2005 00:27:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. adding a table row, without setting same defaults as previous row

2. row heights of table rows added by vba

3. Insert new row at the end of the table

4. Need HaveDeleting Rows From an Access Table Using VB.Net Front End

5. How to Create 2 column table and continue adding rows

6. Format of Rows Added to a Table

7. Adding Rows to a Table

8. add text to table rows

9. Running a macro to add a row in a table

10. Adding row to table is Slooooooow!

11. Adding new rows to related tables on a dataset

12. Help adding Table Rows dynamically Please!

 

 
Powered by phpBB® Forum Software