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

  • Question

  • Hi, 

    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 2010-2013), How can I move cursor after the table or any object (last object) in last page? (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;


    Monday, December 28, 2015 3:26 PM

All replies

  • You asked this exact same question on StackOverflow a few days ago and marked my response as "the answer".

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

    I really don't see the point of bothering people again for the same question...

    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"


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Monday, December 28, 2015 5:03 PM
    Moderator
  • This is for 1 table, I have to move cursor for any object and tableS
    Tuesday, December 29, 2015 7:24 AM
  • I'm afraid your requirement is still not clear...

    And in any case, pressing ENTER is not going to move you to the text area AFTER the table - it will create additional paragraphs within the table.

    Are you asking how to get to the end of a document?

    Or are you asking how to position text at the end of the last page of a document?

    Please be very precise...


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Tuesday, December 29, 2015 6:44 PM
    Moderator
  • In my case, clearly, I have a word document in my application that users must sign them. Therefore, the signature should be at the bottom of the last page. In some documents, Signed easily done but in some documents that end of the document (last page)  is not detectable, Signature image is placed at the end of the TEXT.

    **Signature => User signature image must be placed at the end of document(last page)

    **end of the file is not detectable => There is a table, Picture, Textbox,...  in word document file and after these objects there is no TEXT **

    ** In document, There may be several tables, pictures and textboxes

    Tuesday, December 29, 2015 8:26 PM
  • Hi Mohamad,

    You said that Selection.EndKey doesn’t work, could you provide the detail the result after call this code?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 30, 2015 2:15 AM
    Moderator
  • Notice :

    1) 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.

    2) In document, There may be several tables, pictures and textboxes

    -------------------

    I've used the following command (In Delphi)

    Selection.EndKey(wdUnits.wdStory, WdGoToDirection.wdGoToLast)

    and then, The cursor is placed at the right side of first row of the table (Not inside table) and inserted the signature image, In the event that should be moved to the last text and the last object on the last page and then insert the signature image.

    Wednesday, December 30, 2015 7:41 AM
  • <<The cursor is placed at the right side of first row of the table (Not inside table) and inserted the signature image>>

    This only makes sense if the table has been formatted with "text wrap". You can check my logic by right-clicking the table, selecting "Properties" and seeing whether under "Text wrapping" the value "Around" is selected. If that's the case and you do not want the behavior you're seeing, try clicking "None". Does what's to the right of the table now move below it?

    In the object model, this corresponds to

       objectTable.Rows.WrapAroundText

    False (0) is what you want. If you need to check whether the table has picked up this formatting (it can happen if a user drags it):

       If objectTable.Rows.WrapAroundText = -1 Then objectTable.Rows.WrapAroundText = 0


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Wednesday, December 30, 2015 4:24 PM
    Moderator
  • Hi Mohamad,

    I made a test with VBA code, it seems can’t reproduce that issue even select Around (Text warpping). What’s the result if you try it with VBA code?

    Could you share a sample file on the OneDrive?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 31, 2015 1:47 AM
    Moderator