Word Interop: Duplicate a Table Row Template that consists of more than 1 Row

For those who bump into this:

We are doing some Word MailMerging together with filling up Word Tables with data from Code.
Ran into issues when wanting to duplicate a Template Row that consists of more than 1 row, for the number of Records needed to output.

Ofc we wish to maintain the Template Row formatting etc .. so Copy-Paste it is...

For a Table Data Template that consist of 1 row, no problem:
WordTableRow := WordDocument.Tables.Item(TableIndex).Rows.Item(TemplateIndex);
WordTableRow.Select();
Selection := WordApplication.Selection();
Selection.Copy();
FOR CopyIndex := 1 to NumberOfCopies DO
Selection.Paste();


For a Template that consists of Multiple Rows.. hmmm.. we need to select multiple rows and copy-paste that.
Also, a Range.End >> End is a reserved word >> "End" tends to solve it by the way:
WordTableRow := WordDocument.Tables.Item(TableIndex).Rows.Item(TemplateIndex);
StartPosition := WordTableRow.Range.Start();
IF (TemplateRowCount > 1) THEN
WordTableRow := WordDocument.Tables.Item(TableIndex).Rows.Item(TemplateIndex + (TemplateRowCount - 1));
StopPosition := WordTableRow.Range."End"();
Range := WordDocument.Range(StartPosition, StopPosition);
Range.Select();
Selection := WordApplication.Selection();
Selection.Copy();
FOR CopyIndex := 1 to NumberOfCopies DO
Selection.Paste();


Happy Trails! :)
Sign In or Register to comment.