Getting text from a LibreOffice Writer text selection using Macros Basic

Hi. What LibreOffice macros basic code do I use to put LibreOffice Writer selected text in a string variable?

Learn how to use MRI

Hallo

sub writer_selected_string()
    doc = thisComponent
    selectedString = doc.CurrentSelection.getByIndex(0).getString()
end sub

Thank you. It works.