We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

Writer : How can I set text selection with start and length ? [closed]

asked 2016-01-18 17:24:39 +0200

OfficeNet gravatar image

Hello everyone,

I need to select some text from a start position with a length in LibreOffice Writer.

This is for C# but a macro would be helpful too.

Any help will be very appreciated.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2021-02-14 12:03:39.451617

1 Answer

Sort by » oldest newest most voted

answered 2018-01-22 09:16:16 +0200

librebel gravatar image

updated 2018-01-22 09:54:34 +0200

Hello @OfficeNet,

To select a range of text within the current Writer document, you could use the following macro:

Sub Writer_selectRange( iStartPos As Integer, iLength As Integer )
REM Select a range of text inside the normal text flow of the current Writer document.
REM <iStartPos> : Short Integer specifying the (0-based) index of the first character to select.
REM <iLength>   : Short Integer specifying the number of characters to select; Pass -1 to select till the end.
REM NB. Textfields within the specified range are counted as a single character, no matter how many characters are inside the Textfield.
    Dim oDoc As Object        : oDoc    = ThisComponent
    Dim oViewCursor as Object : oViewCursor = oDoc.CurrentController.getViewCursor()
    Dim oTextCursor as Object : oTextCursor = oViewCursor.Text.createTextCursor()
    oTextCursor.gotoStart( False )
    oTextCursor.goRight( iStartPos, False )
    oTextCursor.goRight( iLength, True )
    oDoc.CurrentController.select( oTextCursor )
End Sub

HTH, lib

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-01-18 17:24:39 +0200

Seen: 150 times

Last updated: Jan 22 '18