none
Move the cursor to the end of a paragraph using Word 2016 VBA RRS feed

  • Question

  • Hello and thanks for your help.

    I am writing a procedure that enters the time on a line in a task diary.  I want to leave the cursor at the end of the line for the user to enter the task.  Here is the code, with my two feeble attempts to move the cursor as comments:

    Public Sub subNewTask()
        Dim dteNewTime As Date
        Dim strNewTime As String

        dteNewTime = Time
        strNewTime = Format(dteNewTime, "hh:mm:ss") + " "
        ActiveDocument.Content.InsertAfter Text:=strNewTime
        ActiveDocument.Paragraphs.Last.Range.Font.ColorIndex = wdBlack
        'Selection.Collapse Direction:=wdCollapsEnd
        'ActiveDocument.Paragraphs.Last.Range.GoTo What:=wdGoToLine, Which:=wdGoToLast
    End Sub

    Please show me how to move the cursor to the end of the line.

    Thanks a million

    Saturday, December 21, 2019 7:15 PM

All replies

  • You insert the text at the end of the document, so try

        Selection.EndKey Unit:=wdStory


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, December 21, 2019 7:42 PM