Copy and paste a table

H

hals_left

Hi,
Some questions on replicating tables

Whats the best way to reproduce exact copies of a table without mail
merge? I'd like to have a paragrah/space between each table and then
access the latest table to write to the cells.

How can I position the cursor after the last tabekl to insert a
paragraph / carriage return in the right place.

The code below doesnt work because the table copy is not created as a
new table. If it does have to become one continous table, (not a hige
problem) how do I select and copy the bottom n rows each time?

I have an image in right hand side vertically merged cells, but this
stops me accessing cells by row,cell values to put data in them. Is
thier a workaround to this so that the image is repeated alsong with
the table or another way to access and write to vertically merged cells

Thanks
hals_left



While Not (objRS.EOF)

' add a paragraph at the end
ActiveDocument.Tables(intTable).Select
Selection.TypeParagraph

'add a copy of the last table
ActiveDocument.Tables(intTable).Select
Selection.Copy
Selection.Paste
intTable = intTable + 1

'write to latest table
With ActiveDocument.Tables(intTable)
.Rows(2).Cells(2).Select
Selection.Text = objRS(0)

.Rows(3).Cells(2).Select
Selection.Text = objRS(1)
End With
objRS.MoveNext
wend
 
J

Jean-Guy Marcil

hals_left was telling us:
hals_left nous racontait que :
Hi,
Some questions on replicating tables

Whats the best way to reproduce exact copies of a table without mail
merge? I'd like to have a paragrah/space between each table and then
access the latest table to write to the cells.

How can I position the cursor after the last tabekl to insert a
paragraph / carriage return in the right place.

The code below doesnt work because the table copy is not created as a
new table. If it does have to become one continous table, (not a hige
problem) how do I select and copy the bottom n rows each time?

I have an image in right hand side vertically merged cells, but this
stops me accessing cells by row,cell values to put data in them. Is
thier a workaround to this so that the image is repeated alsong with
the table or another way to access and write to vertically merged
cells

Try something like this. I tested it with a document that contained a single
table followed by a single ¶.
The table had the first column merged and contained a picture. To the right
of this merged first column there were 7 rows and 2 more columns.
Of course, I did not have a file object to play with, so I modified the
While condition to make it easier to test.

I do not use the Selection object so it is easier to handle and runs faster.
Also, it does not disturb the user selection.

'_______________________________________
Dim objRS As Long
Dim intTable As Long
Dim docRange As Range
Dim tblRange As Range

objRS = 1
intTable = 1
Set tblRange = ActiveDocument.Tables(1).Range

While objRS < 7
Set docRange = ActiveDocument.Range
' add a paragraph at the end
With docRange
.InsertParagraphAfter

'add a copy of the first table
.Collapse wdCollapseEnd
.FormattedText = tblRange
End With

intTable = intTable + 1

'write to latest table
With ActiveDocument.Tables(intTable).Range
.Cells(4).Range.Text = objRS
objRS = objRS + 1

.Cells(6).Range.Text = objRS
objRS = objRS + 1
End With
Wend
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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