Share via

PasteAppendTable Question

Anonymous
2013-05-23T20:00:46+00:00

I am working on a code that appends some data copied from excel and appended to a current table in a word document. The problem I am having is that my PasteAppendTable command is not working correctly. I have listed my code below:

Sub ChangeTable()

Dim rngParagraphs As Range

Set rngParagraphs = ActiveDocument.Range( _

Start:=ActiveDocument.Tables(3).Range.Start, _

End:=ActiveDocument.Tables(3).Range.End)

rngParagraphs.Style = "Table Columns 2"

rngParagraphs.Rows.Last.Select

Selection.InsertRowsBelow (1)

Selection.PasteAppendTable

rngParagraphs.Style = "Table Grid"

End Sub

I thought maybe I could move the cursor to the first cell of the new last row and that would fix things but I haven't been able to figure that out either. Any help is greatly appreciated!

Thanks,

Dane

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2013-05-23T22:21:42+00:00

    You don't say what you mean by "not working correctly".  However, there is no need to insert a new row after the last row of the table.  If the selection is in the last row of the table, the cells from the clipboard will be pasted after that row:

    You could use the following to add the cells to the third table in the document

    ActiveDocument.Tables(3).Rows(ActiveDocument.Tables(3).Rows.Count).Select

    With Selection

        .Collapse wdCollapseStart

        .PasteAppendTable

    End With

    Was this answer helpful?

    0 comments No comments