Apache OpenOffice (AOO) Bugzilla – Issue 73094
Runtime error when loading Calc template with simple Basic code
Last modified: 2013-02-24 21:08:36 UTC
I found a way to display the name of the current sheet function GetSheetName() GetSheetName = ThisComponent.getCurrentController.getActiveSheet.getName() end function However, if I call GetSheetName() in a formula, save it as a template (.ots), and open it, I get an error BASIC runtime error. An exception occurred. Type: com.sun.star.lang.DisposedException Message: . The error happens on my Windows XP and OOo 2.1, but there is no error with my Linux and OOo 2.1.
Created attachment 41869 [details] test document
jsc -> as: can you take a look on it. Seems that ThisComponent returns different values or is not initialized in the same way. Timing issue! Or do you have a different idea how to solve. StarDesktop.getCurrentComponent.getCurrentController.getActiveSheet.getName() won't work as well
AS->JSC: As discussed with you ... seams to be a problem of calc itself. getActiveSheet() is not valid during loading of documents based on templates.
accepted
Using getActiveSheet won't work anyway in your scenario if you would have more than one sheet. The function is calculated during the load process. What should active sheet be in this case? Be careful with getCurrentComponent, getCurrentControler or for example getActiveSheet. Think about the semantic of these functions ;-) Solution: change your macro to function GetSheetName(sheetnumber as Integer) msgbox sheetnumber GetSheetName = ThisComponent.getSheets().getByIndex(sheetnumber-1).Name end function use a parameter to reference the sheet where you call the function!!! In the document you can simply use =getSheetName(Sheet(a1)) I hope this helps
closed