I have a macro in LibreOffice Writer that changes the case of the word the cursor is in. It works great except when the cursor is in a footnote, where it faults out. The partial code:

Document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") 

oVC = ThisComponent.CurrentController.getViewCursor
oTC = ThisComponent.Text.createTextCursorByRange(oVC) ' <-the footnote error
ctext = oTC.string ' get selected text

The next to last line, defining oTC, is where the error occurs. Apparently the .Text spec in that line doesn't include footnotes, which is what I also gather reading Andrew's OOME book. But I haven't been able to figure out how to generalize the macro so it will work both in the main document and in footnotes. Any help would be appreciated.

1 Answer 1

oTC = oVC.getText().createTextCursorByRange(oVC)


How does this work? It gets the Text object from oVC. In your case, this is different from the one given by ThisComponent, because the view cursor is located in the footnote area rather than the main body.

Cells also have their own Text objects that are distinct from the main body. oVC.getText() works when located in cells as well.

The property ThisComponent.Text and the method ThisComponent.getText() do the same thing.

  • Absolutely perfect. I saw that Andrew wrote to use getText instead of Text for other text streams, but couldn't figure out how to implement it. My footnotes thank you, and I thank you much!
    – Paul B.
    Jan 29, 2018 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.