Copy row and past rows not centered 
Author Message
 Copy row and past rows not centered

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



Mon, 22 Sep 2003 13:30:43 GMT  
 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



Wed, 24 Sep 2003 02:31:08 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. copy row to row

2. table row text will not show after row insert

3. group every 8 rows in 1 row

4. Calculating a field from same row for each row/record in form

5. Getting row number variable from a selected row in Excel

6. adding a table row, without setting same defaults as previous row

7. row heights of table rows added by vba

8. Determining actual row height, or setting maximum row height

9. Rows.RemoveAt v. Rows.Delete

10. Add row to datatable from datagrid without leaving current row with cursor

11. Err No rows at, duplicate table and row names

12. Retrieve Row Index from a Row Object

 

 
Powered by phpBB® Forum Software