Calc: Get document object from sheet object

If I have a sheet object (ScTableSheetObj), is there any way to determine its parent (ScModelObj), i.e., the document in which the sheet resides ?

I have looked for something like a .Parent property, or .getParent method in the sheet object, but don’t see anything relevant.

One cannot always rely on ThisComponent, as the sheet could be in a different document from which the macro is running.

DrawPage->Forms->Parent

You may want to look at Open Office Macros Explained by Andrew Pitonyak. PDF here → OOME

“One cannot always rely on ThisComponent, as the sheet could be in a different document from which the macro is running.”

For example?

To Ratslinger: Thanks, did not thing of going through drawPage! Had just assumed there would be a more direct way to get at the parent of a sheet. I do read OOME, and Useful Macro Information; those are both great resources.

To Mauricio: So far as not relying on ThisComponent, one may have created an object which refers to a sheet in a different document. (For, say, copying data from one to the other.) ThisComponent refers to the document where the macro is running, which in this case would not be the object containing the other sheet.

I’m in the process of refactoring my codebase to where routines that “touch” a document’s child objects have an optional document object parameter. If I don’t include it, it’ll “find” ThisComponent and use it. But if I do pass a document object, it’ll use that one instead. It’s the end result of a question I asked about optional parameters…