Need some help with macro

I have a basic macro that does some things in calc, it works fine but if i open a writer doc it of course crashes. In looking at the ThisComponent i see it has a Title property so i thought, ok, if its the wrong title i will just exit the macro, but no amount of twiddling will let me test this property

Function PortfolioGain() as Currency
   Dim doc As Object
   Dim sheet As Object
   Dim sum as Variant

    doc = ThisComponent
    if doc.CurrentController.Title != "Stocks.ods" Then 
       Exit Function

I also just noticed that when writer is open and the foreground window that doc (ThisComponent) appears to be null, so i tried this test
but that also doesnt work.

  doc = ThisComponent
    if IsNull(doc) then
       Exit Function

What i need to do is to only proceed in the macro if the spreadsheet ‘Stocks.ods’ is the active sheet
Can anyone suggest a simple test i could use?

My 2 cents: go where the experts live, i.e. the libreoffice forums. Your chances will be much higher. In all my years here, I don’t think I’ve seen more than a couple of threads re. LO maxros.

Yup, good idea. I just now posted over on the libre office forum - thanks