Rahul Bajaj
Rahul Bajaj

Reputation: 135

Delphi Word automation: how to insert text after a table?

I have a Microsoft Word document with a table in it. My problem is that I need some text after the table but when I use Selection.TypeText(Text) after the table, the text is shown inside the table and not after/outside the table. How can I insert text after the table?

Code shown below:

Table := MSWord.ActiveDocument.Tables.Add(MSWord.Selection.Range, 2, 1);
Table.Cell(1, 1).Range.Text := 'GreenDay';
Table.Cell(2, 1).Range.Text := 'Kiss';
MSWord.Selection.TypeText('cdassda');

My second problem is that I am not able to append data to a new page:

MSWord.Selection.Goto(wdGoToPage, wdGoToLast);

Upvotes: 1

Views: 1721

Answers (1)

MartynA
MartynA

Reputation: 30715

Try this:

Table.Cell(1, 1).Range.Text := 'GreenDay';
Table.Cell(2, 1).Range.Text := 'Kiss';
MSWord.Selection.EndKey( Unit:=wdStory);
MSWord.Selection.TypeParagraph;
MSWord.Selection.TypeText('cdassda');

Regarding your second point, this works for me:

//MSWord.Selection.Goto(wdGoToPage, wdGoToLast);

MSWord.Selection.EndKey( Unit:=wdStory );
MSWord.Selection.InsertBreak( Type:=wdPageBreak);

MSWord.Selection.TypeText('next page');

Upvotes: 3

Related Questions