Insert Row Beneath Last Row in Table

A

Andibevan

Hi There,

I have some code that I have to run from within Excel. I have worked out
how to locate a table and then manipulate the contents, but I can't work-out
how to insert a new row below the last row of the table?

Thanks

Andy
 
H

Helmut Weber

Hi,

like this:

ActiveDocument.Tables(1).Rows.Add

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
A

Andibevan

Thanks Helmut - How do I then refer to the cells within this last row?

Alternatively - what method do I use to return /determine the last row of a
table?
 
H

Helmut Weber

Hi,

just one of some ways:

With ActiveDocument.Tables(3).Rows.Last
MsgBox Len(.Cells(2).Range.Text)
End With

I hope, the use of "activedocument" doesn't confuse you.
You have do adapt the code to work from Excel.

An note that ...cells(2).range.text contains
not only the text in that cell, but the two
characters, that make up the end-of-cell mark,
in addition.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

JBNewsGroup

Hi Andibevan,

The last row would be the number of rows:

ActiveDocument.Tables(1).Rows.Count

You could then set a Range to that row.

Jerry Bodoff
 
A

Andibevan

Thanks Helmut - I have used vba in excel loads but never had a requirement
within Word before. Do you know if the Rows.Last method works when
controlling word from within excel?
 
D

Doug Robbins

Dim newrow as Row
Set newrow = ActiveDocument.Tables(1).Rows.Add

newrow now can be used to refer to the row that you just added.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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