Ask Your Question
0

getActiveSheet error on initial file load

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

jaM gravatar image

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

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

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
0

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

jaM gravatar image

Apparent bug

edit flag offensive delete link more
0

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

Ratslinger gravatar image

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

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()
edit flag offensive delete link more

Comments

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 +0100 )edit

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

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

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

Ratslinger gravatar imageRatslinger ( 2018-12-20 17:46:59 +0100 )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 +0100 )edit

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

jaM gravatar imagejaM ( 2018-12-20 18:20:28 +0100 )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 +0100 )edit

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

jaM gravatar imagejaM ( 2018-12-20 18:34:43 +0100 )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 +0100 )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 +0100 )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 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 28 times

Last updated: Dec 21 '18