1
votes

I have a Word document with 2 pages and I've insert table that table start from page one and continues until the middle of the second page(Only one table exist in document).

In Delphi(XE7) and with OLE automation(variant and Office 2013), How can I move cursor after the table? (Manually in word document file, I have repeatedly press Enter key)

For this purpose, These codes will not work :

Selection.GoTo(wdGoToItem.wdGoToPage, wdGoToDirection.wdGoToLast);

and :

Selection.EndKey(wdStory, EmptyParam);

and :

lvParag := ActiveDocument.Paragraphs.First;
Result := Range.Sentences.First.End - 1;
1
Select the table, then move one character forward?Jan Doggen
@JanDoggen, How do I select table or other objects?Mohamad
Something like Selection.Tables[1].Select; Selection.Collapse(0); // wdCollapseEndkobik

1 Answers

2
votes

There are various ways to go about it. The one I use is to get the table's Range then collapse the Range. Something like this (VBA, but you shouldn't have any difficulty "translating" it):

Dim tbl as Word.Table, rng as Word.Range
Set tbl = ActiveDocument.Tables(1)
Set rng = tbl.Range
rng.Collapse wdCollapseEnd 'Word.WdCollapseDirection.wdCollapseEnd
'If you need to show the user the Selection
rng.Select()
'Otherwise, continue to work with the Range object, adding text, for example:
rng.Text = "text following the table"
'and formatting it
rng.Style = "style name"