Star Office v 3.5-STARBASIC, Current Component Context workaround? (Property or method not found: sheets)
===

This seems to be a common problem, but I have yet to find a workaround. I hope somebody can help me. The problem seems to be very common, and well understood. However the solution seems to be non-existent.

I am writing a macro in Star Office Ver 3.5. My objective is to get an instance of a "Sheet" object so I can manipulate cell contents via code. The Star Office documentation says to do the following:

    Doc   = StarDesktop.CurentComponent
    Sheet = Doc.Sheets(0)

This will, in theory, return a "Sheet" object that you can then manipulate. This code does indeed work fine when it it run from inside the spreadsheet. The first line gets a reference to the "CurrentComponent", which is the spreadsheet document, and the second line selects a specific sheet.

However, when this code is run from inside the macro development IDE it fails. The reason is easy enough to understand: When you are working in the IDE, the "CurrentComponent" is the IDE, NOT the spreadsheet document. And since the IDE is not the spreadsheet document, ti does not contain a collection of sheets. Consequently, when the macro is run from the IDE, "Doc.Sheets(0)" collection is out of scope, and thus produces the error "BASIC runtime error. Property or method not found: Sheets". To make matters worse, if you set a watch or a breakpoint for debugging, the context of "CurrentComponent" switches from the spreadsheet document to the IDE. This tends to make debugging impossible, as when the context switches to the debugger there I cant access the properties or the spreadsheet.

I am looking for workaround for this problem. The Microsoft solution would be to select the current application, iterate through the collection of open documents, and find one that is a spreadsheet. Pseudo-code for this solution follows:

    oApplication = currentApplication()
    oDocuments = oApplication.documents()
    for each oDocuments as oThisDoc {
       if oThisDoc.type = "workbook" then {
           oThisSheet = oThisDoc.sheets(0)
       }
    }

So.... What is the equivalent in Star BASIC? It seems that there top-level object is called "StarDesktop". However, I was unable to find anything that looked like a collection of currently open documents when I looked through this object. This issue is a very common problem and it would be nice if we could provide a work-around to the community.
