Tables[1].Rows.Add returns null if table has vertically merged cel

P

Prasad More

The following line of code in my application insert a new row after the last
row in table.

Row tRow = range.Tables[1].Rows.Add(ref missingValue);

Where
1. tRow is object of Microsoft.Office.Interop.Word.Row class
2. range is object of Microsoft.Office.Interop.Word.Range

This code works fine when table contains no vertically merged cells. If the
table contains vertically merged cells, Rows.Add returns null value.

Any idea "Why Rows.Add returns null when table contains vertically merged
cells"?.

Thanks,
Prasad
 
T

Tony Jollans

Why? is a difficult question to answer. It is, however, not possible to
directly address individual rows of tables with vertically merged cells,
even though there may be no merged cells in the row in question.

One workaround would be to address the first cell of the new row and then
expand the range:

range.Tables(1).Rows.Add
Set tRow = range.Tables(1).Cell(range.Tables(1).Rows.Count, 1).Range
tRow.Expand wdRow

(this assumes the row is added at the end of the table)
(this is also VBA so you'll need to tweak it slightly)
 
P

Prasad More

Hi Tony,

Thank you for reply. The issues that I am facing is I cannot access
individual rows of a table when there are vertically merged cells into it and
the second issue is Add method fails. So when the Add method fails to return
the reference to added row, there is no way I can access first cells and
expand the range.

Best Regards,
Prasad

Tony Jollans said:
Why? is a difficult question to answer. It is, however, not possible to
directly address individual rows of tables with vertically merged cells,
even though there may be no merged cells in the row in question.

One workaround would be to address the first cell of the new row and then
expand the range:

range.Tables(1).Rows.Add
Set tRow = range.Tables(1).Cell(range.Tables(1).Rows.Count, 1).Range
tRow.Expand wdRow

(this assumes the row is added at the end of the table)
(this is also VBA so you'll need to tweak it slightly)

--
Enjoy,
Tony

Prasad More said:
The following line of code in my application insert a new row after the
last
row in table.

Row tRow = range.Tables[1].Rows.Add(ref missingValue);

Where
1. tRow is object of Microsoft.Office.Interop.Word.Row class
2. range is object of Microsoft.Office.Interop.Word.Range

This code works fine when table contains no vertically merged cells. If
the
table contains vertically merged cells, Rows.Add returns null value.

Any idea "Why Rows.Add returns null when table contains vertically merged
cells"?.

Thanks,
Prasad
 
T

Tony Jollans

Sorry, but I don't know why the Add should fail. What error code does it
give?

--
Enjoy,
Tony

Prasad More said:
Hi Tony,

Thank you for reply. The issues that I am facing is I cannot access
individual rows of a table when there are vertically merged cells into it
and
the second issue is Add method fails. So when the Add method fails to
return
the reference to added row, there is no way I can access first cells and
expand the range.

Best Regards,
Prasad

Tony Jollans said:
Why? is a difficult question to answer. It is, however, not possible to
directly address individual rows of tables with vertically merged cells,
even though there may be no merged cells in the row in question.

One workaround would be to address the first cell of the new row and then
expand the range:

range.Tables(1).Rows.Add
Set tRow = range.Tables(1).Cell(range.Tables(1).Rows.Count, 1).Range
tRow.Expand wdRow

(this assumes the row is added at the end of the table)
(this is also VBA so you'll need to tweak it slightly)

--
Enjoy,
Tony

Prasad More said:
The following line of code in my application insert a new row after the
last
row in table.

Row tRow = range.Tables[1].Rows.Add(ref missingValue);

Where
1. tRow is object of Microsoft.Office.Interop.Word.Row class
2. range is object of Microsoft.Office.Interop.Word.Range

This code works fine when table contains no vertically merged cells. If
the
table contains vertically merged cells, Rows.Add returns null value.

Any idea "Why Rows.Add returns null when table contains vertically
merged
cells"?.

Thanks,
Prasad
 

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