Appending tables

R

rahul4real

I have got a word document that already contains a table. I need to
write a MS word macro to append one more table after the existing table
in the same word document.When i write the following code:
set oTable = oDoc.Tables.Add(.......)

i get the new table overwritten on to the existing table. How can i
overcome this problem...
Please help!!
Thanks in advance
 
D

Doug Robbins - Word MVP

Dim trange As Range
Dim otable As Table
With ActiveDocument
Set trange = .Range
trange.Collapse wdCollapseEnd
Set otable = .Tables.Add(trange, 2, 2)
End With

or, if you want a space between the two tables

Dim trange As Range
Dim otable As Table
With ActiveDocument
.Range.InsertAfter vbCr
Set trange = .Range
trange.Collapse wdCollapseEnd
Set otable = .Tables.Add(trange, 2, 2)
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, originally posted via msnews.microsoft.com
 

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