3

I created and saved a spreadsheet that uses a macro for an interpolation task. When I open the document again all the cells calling the function are shown as #NAME? although the document still seems to contain the macro: When I open Tools | Macros | Organize Macros... | LibreOffice Basic Macros | (the document) | util | Module1 and click 'Edit' I can edit the source code as before.

Does anybody know what's wrong? How can I recover my file? I switched the security setting to 'Low (not recommended)', just be be sure, but only after having created and saved the file.

user829755
  • 1,489
  • 13
  • 27
  • What is the "util" in your Macro organize path? If it is a library, where it is stored in? Why you do not simply store your user defined function in the Standard library of your document? – Axel Richter Oct 19 '14 at 07:32
  • this helped! @AxelRichter: there was a formatting problem in my question, I fixed it. util was meant to become a library of general utility functions. Following your comment I replaced module "Module1" in library "util" with module "util" in library "Standard" and now it works. To me this appears to be a little overdesigned. Thank you. If you post this as an answer I can accept it. – user829755 Oct 19 '14 at 11:25

3 Answers3

2

In libreoffice or openoffice basic it is not possible to run a user defined function, which is stored in a library except the Standard libraries, as formula in a cell. Although it is possible to have functions stored in libraries, the UDFs have to be in the Standard libraries. They (the UDFs) then of course can call functions in libraries if those libraries are loaded.

UDFs in libreries

The UDF can be called in a cell as =UDF(). The UDF2 can also be called in a cell as =UDF2(). It then loads the library "util", if it is not already loaded yet, and returns the result of utilUDF().

See also http://www.openoffice.org/documentation/manuals/userguide3/0312CG3-CalcMacros.pdf#7 "Write your own functions" page 7 to 12.

Greetings

Axel

Axel Richter
  • 56,077
  • 6
  • 60
  • 87
0

I had the same problem with a macro defined with Sub Foo. I changed that to public function Foo, and it worked.

NB: after 20 years of software development, the LibreOffice API is the crappiest one I've had the "pleasure" of working with. The documentation is horrible, spread all over the place, littered with Uyghur, or completely missing. The LibreOffice macro IDE is also extremely unhelpful.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • Dan forgot to add that e.g. their "littered with Uyghur" was not a bug, but incomplete translation in the localized help identified in https://bugs.documentfoundation.org/show_bug.cgi?id=137725, so that was using random links combined with some not-too-active native language team. (Not mentioning that "Horrible" is completely not descriptive, referencing to a documentation page without telling what needs improving.) – Mike Kaganski Jun 20 '22 at 10:51
0

Remember to allow macros to run : Tools, Options, Security, Macro Security, Trusted Sources (or security level).

François Breton
  • 1,158
  • 14
  • 24