getActiveSheet error on initial file load

  1. Win10-64 Pro ver1809 LO 6.1.4.2

  2. Following simple test macro is throwing “Object not set” error under 6.1.4.2, works on recalculations; Works under LO 6.1.3.2

Function getActiveSheet

    cntlr = ThisComponent.getCurrentController()
    MsgBox "before getActiveSheet"
    sSheet = cntlr.getActiveSheet()
   MsgBox "after  getActiveSheet"
   MsgBox sSheet.RangeAddress.Sheet
 End Function
  1. test file attached ‘test.ods’

  2. Please advise and thank you in advance.test.ods

Hello,

You have not provided a Function but rather a Sub routine. What you are attempting requires a Function. This Function will return the name of the active sheet:

Function getActiveSheet
  cntlr = ThisComponent.getCurrentController()
  MsgBox "before getActiveSheet"
  sSheet = cntlr.getActiveSheet()
  MsgBox "after  getActiveSheet"
  MsgBox sSheet.RangeAddress.Sheet
  getActiveSheet = sSheet.Name
End Function

This is your routine with Sub changed to Function and a return value added for the sheet name.

Also use the correct call in the cell:

 =getActiveSheet()

or

 =GETACTIVESHEET()

are you suggesting the reason of the failure is it’s a function?..why write a sub and then create a function to call it when the only purpose of the test was to demo the error condition via MsgBox.

Note that the sample provided contained a Sub and not a Function.

My error in not looking at version. Will download & test.

I feared this would be the case, since no other reports were filed…I’m really lost why my Win10-64pro 1809 on a HP laptop would fail…thank you for your time and effort…Jon A. Miller

Ratslinger: so the macro function ran properly on the initial file load from either a command line or open with LO 6.1.4.2 on linux Mint…is that correct? The comment that it ran with a RUN macro would suggest the file was already loaded…correction: this is a Win10-64home not pro

@jaM2 Sorry for the confusion I have added here. As you may see I had deleted my previous comment because I again did not read all the information correctly. You are correct in getting the error on initial load. While:

  cntlr = ThisComponent.getCurrentController()

creates no problem, the other statements using cntlr do generate the error on document load in v6.1.4 but not v6.1.3. Must be a new bug.

Again sorry for my errors. Was not looking closely at version and confused myself with the Sub in the sample & the Function in the question.

Not a problem…appreciate the testing…

@jaM2 Have now used MRI to try & isolate the problem further. ThisComponent is available but nothing after that until the sheet is completely loaded but it is confusing as to how it is seeing the cell function if it isn’t completely loaded. Again this only in v6.1.4.

Also the sub does work on the Open Document event. Has me curious and will look at again later.

Tested “Open Document” with system clock, and cell functions are being executed before the “Open Document” event is thrown

@Ratslinger I’m going to add an answer this is apparently a bug unless you believe further testing is necessary

@jaM2 At this point it I have nothing further. You should file a bug report on it.

Any development on that bug ? Still there in 6.2.4.2.

https://bugs.documentfoundation.org/show_bug.cgi?id=123005

Thanks Ratslinger.
The workaround with View Created Event (thanks to B. Marcelly (2014 !)) is doing the job for the moment.
(mentionned by Armin Linder in Bug 125042)
The original link is dead but it is well explained there:

Apparent bug