Copy a row inside an other table

A

Alex St-Pierre

Hi!
I split a table into a lot of pages using macro and I would like to
copy-paste the first row of table#1 at the top of table #2, etc.
Something like the following but using the object method.
Thank you!
Alex
docWord.Tables(2).Rows.Add BeforeRow:=oRange.Tables(2).Rows(1)
docWord.Tables(1).Rows(1).Range.Select
Selection.Copy
docWord.Tables(2).Rows(1).Range.Select
Selection.Paste 'Gives error 438..
 
J

Jean-Guy Marcil

Alex St-Pierre said:
Hi!
I split a table into a lot of pages using macro and I would like to
copy-paste the first row of table#1 at the top of table #2, etc.
Something like the following but using the object method.
Thank you!
Alex
docWord.Tables(2).Rows.Add BeforeRow:=oRange.Tables(2).Rows(1)
docWord.Tables(1).Rows(1).Range.Select
Selection.Copy
docWord.Tables(2).Rows(1).Range.Select
Selection.Paste 'Gives error 438..

Try something like this:

Dim tblPaste As Table
Dim i As Long
Dim rowCopy As Row

With ActiveDocument
Set rowCopy = .Tables(1).Rows(1)
For i = 2 To .Tables.Count
With .Tables(i)
.Rows.Add (.Rows(1))
.Rows(1).Range.FormattedText = rowCopy.Range.FormattedText
.Rows(2).Delete
End With
Next
End With
 
A

Alex St-Pierre

Thank's a lot. It works very well.
I'm wondering if there are 2 rows to copy from table #1 to table #2 (first
two row), is it possible to copy the 2 rows at the same time by setting
rowCopy equal to the first two rows?
Alex
 
J

Jean-Guy Marcil

Alex St-Pierre said:
Thank's a lot. It works very well.
I'm wondering if there are 2 rows to copy from table #1 to table #2 (first
two row), is it possible to copy the 2 rows at the same time by setting
rowCopy equal to the first two rows?

Modify the code I posted and try it! You would probably need two row
objects... Or try without row objects and use the Range object instead...
 

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