Ask Your Question

getActiveSheet error on initial file load

asked 2018-12-20 17:17:50 +0200

jaM gravatar image

updated 2018-12-20 17:21:10 +0200

1) Win10-64 Pro ver1809 LO

2) Following simple test macro is throwing "Object not set" error under, works on recalculations; Works under LO

Function getActiveSheet

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

3) test file attached 'test.ods'

4) Please advise and thank you in advance.C:\fakepath\test.ods

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-12-21 17:04:31 +0200

jaM gravatar image

Apparent bug

edit flag offensive delete link more

answered 2018-12-20 17:29:33 +0200

Ratslinger gravatar image

updated 2018-12-20 17:33:17 +0200


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:



edit flag offensive delete link more


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.

jaM gravatar imagejaM ( 2018-12-20 17:41:24 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2018-12-20 17:41:51 +0200 )edit

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

Ratslinger gravatar imageRatslinger ( 2018-12-20 17:46:59 +0200 )edit

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

jaM gravatar imagejaM ( 2018-12-20 18:09:42 +0200 )edit

Ratslinger: so the macro function ran properly on the initial file load from either a command line or open with LO on linux 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

jaM gravatar imagejaM ( 2018-12-20 18:20:28 +0200 )edit

@jaM 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.

Ratslinger gravatar imageRatslinger ( 2018-12-20 18:32:05 +0200 )edit

Not a problem...appreciate the testing...

jaM gravatar imagejaM ( 2018-12-20 18:34:43 +0200 )edit

@jaM 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.

Ratslinger gravatar imageRatslinger ( 2018-12-20 19:03:07 +0200 )edit

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

jaM gravatar imagejaM ( 2018-12-20 20:14:50 +0200 )edit

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

jaM gravatar imagejaM ( 2018-12-21 16:55:45 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-12-20 17:17:50 +0200

Seen: 45 times

Last updated: Dec 21 '18