How do I get content of a text cursor in Libreoffice Writer?

49 Views Asked by At

I want to get content of a text cursor in Libreoffice Writer. In this case, the content of the first word in the document.

I tried the code below. The last line in the sub gets me the content of the whole document not of the first word. I do not want that. I want the content / string of the first word.

Sub Test4
  Cursor = ThisComponent.Text.createTextCursor()
  Cursor.gotoStart(False)
  Cursor.gotoEndOfWord(True)
  msgbox Cursor.Text.getString()
End Sub
1

There are 1 best solutions below

0
Jan Siebert On

The right answer is this.

Sub Test4
  Cursor = ThisComponent.Text.createTextCursor()
  Cursor.gotoStart(False)
  Cursor.gotoEndOfWord(True)
  msgbox Cursor.getString()
End Sub