Add a row after the last row of a Word table

N

Newbie

Hello,

Now, I know how to add a row in a Word table. But I need to make sure that
this row will be added after the last row of the table. How can I do that
with VBA?
Thanks for your help.
 
J

Jay Freedman

If you call the Table.Rows.Add method and you don't supply a value for
the optional BeforeRow parameter, the new row will be added after the
last row.

To prove it to yourself, run this code in a document that contains at
least one table:

Sub Test()
Dim nRow As Row
With ActiveDocument.Tables(1)
Set nRow = .Rows.Add
If nRow.Index <> .Rows.Count Then
MsgBox "Not the last row"
End If
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
N

Newbie

Thanks again Jay!

Jay Freedman said:
If you call the Table.Rows.Add method and you don't supply a value for
the optional BeforeRow parameter, the new row will be added after the
last row.

To prove it to yourself, run this code in a document that contains at
least one table:

Sub Test()
Dim nRow As Row
With ActiveDocument.Tables(1)
Set nRow = .Rows.Add
If nRow.Index <> .Rows.Count Then
MsgBox "Not the last row"
End If
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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