How can I move cursor to end of table In word application

蹲街弑〆低调 提交于 2019-12-24 16:45:59

问题


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:


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"


来源:https://stackoverflow.com/questions/34393260/how-can-i-move-cursor-to-end-of-table-in-word-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!