Confusing description in the "The current document - Working with Documents - LibreOffice BASIC Programming Guide - The Document Foundation Wiki" section

In the The current document - Working with Documents - LibreOffice BASIC Programming Guide - The Document Foundation Wiki section:

You should instead use Basic object ThisComponent. It returns the document object on which the macro is run. If you start the macro from the IDE, ThisComponent will still find and return your document.

The emphasized portion makes little sense to me as it does not elaborate on where the document object comes from.

IMHO this section should probably be merged into ThisComponent - The StarDesktop - Working with Documents - LibreOffice BASIC Programming Guide - The Document Foundation Wiki, which gives the rather proper explanation:

ThisComponent returns the last previously active document.

I’ve made a change which should mitigate this issue.

You have the currently active document. You have the last active document. The macro can live inside a document or it can live outside a document.

If you run the macro from the IDE and if the macro does not live inside of a document, then this component will indeed refer to the last active document.

If I click on a button inside of a document that causes a macro to be run and that macro does not live in the currently active document or if it does live in the currently active document then this component refers to the currently active document.

Now what does this component refer to if the macro lives inside of a document that was not the last active document and you run it from the IDE?

Hi @brlin

Thank you for the remarks on the contents of the Basic Guide.

Please, can you bring your remarks directly to the wiki? The wiki has mean to start discussion in its page contents.

See Contributing to the LibreOffice BASIC Programming Guide - The Document Foundation Wiki

Cheers
Olivier

1 Like

Got it, thanks for the heads-up!