Find last cell in Word Table

S

Sal

Hi,

I would like to write a macro that finds that last cell in a table and
inserts a new row (which I have saved as AutoText).

Thanks
 
D

Doug Robbins - Word MVP

The following will set lastcell as the last cell in the first table in the
document

Dim lastcell As Range
With ActiveDocument.Tables(1)
Set lastcell = .Cell(.Rows.Count, .Columns.Count).Range
End With


--
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
 
H

Helmut Weber

Hi Sal,

you don't have to select anything.

Have a look at this one:

Dim rTbl As Range
Set rTbl = ActiveDocument.Tables(1).Range.Characters.Last.Next
rTbl.Collapse
NormalTemplate.AutoTextEntries("TableRow").Insert _
Where:=rTbl, _
RichText:=True

In case you want to select the last cell in a table
with split and merged cells, especially if
the merged and split cells are in the last row, try:

With ActiveDocument.Tables(1).Range
.Cells(.Cells.Count).Select
End With


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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