
Copy row and past rows not centered
Glenn
Try the code below. I think it does what you are looking for. I wasn't aware
of the table rows being positioned at the left margin instead of centered
when pasted.
--
/Anna Bohman
Bra Utbildning AB, Sweden
-------------------------------------------------------------------------
Dim First As Integer
Dim iTotal As Integer
Dim oTbl As Table
Dim oLastRow As Row
Dim i As Integer
Dim sText1 As String
Dim sText2 As String
Dim sText3 As String
First = 10 'Number of rows - replace with your code
Set oTbl = ActiveDocument.Tables(1)
Set oLastRow = oTbl.Rows.Last
iTotal = oTbl.Rows.Count + First
'Get the contents of each cell on the last table row, exclude 2 chrs
sText1 = Left$(oLastRow.Cells(1).Range, _
Len(oLastRow.Cells(1).Range) - 2)
sText2 = Left$(oLastRow.Cells(2).Range, _
Len(oLastRow.Cells(2).Range) - 2)
sText3 = Left$(oLastRow.Cells(3).Range, _
Len(oLastRow.Cells(3).Range) - 2)
'Position the insertion point
oTbl.Rows(4).Select
Selection.Collapse wdCollapseStart
Selection.InsertRowsAbove First 'add rows
'add text
For i = iTotal - First To iTotal - 1
oTbl.Cell(i, 1).Range = sText1
oTbl.Cell(i, 2).Range = sText2
oTbl.Cell(i, 3).Range = sText3
Next
Quote:
> In Word this code copies one row and pasts a number of rows depending on
> the "First"
> parameter value in a table.
> How do I make the new rows be the same column offset as the existing rows
> i.e. inline. They appear flush to the left side and the existing table of
> rows are centered.
> Private Sub Document_open()
> First = ActiveDocument.MailMerge.DataSource.DataFields("MR").Value
> ActiveDocument.Tables(1).Rows(3).Range.Copy
> Set myTable = ActiveDocument.Tables(1)
> Set Newrow = myTable.Rows.add(BeforeRow:=myTable.Rows(4))
> Newrow.Range.Collapse Direction:=wdCollapseEnd
> For i = 1 To (First - 2)
> Newrow.Range.Paste
> Newrow.Range.Collapse Direction:=wdCollapseEnd
> Next i
> End Sub
> Glenn