Description: If I copy or export/import a macro from the default "Standard" library to a library in a new sheet that I've given a custom name to so I can password protec the macro I get a lot of errors and the macros don't run. "wrong number of parameters" if I try to run the macro from the library with the custom name so I can protect it through Tools > Macros > Run Macro. "run time error" or "syntax error - already defined" if I try to run them from the organizer. If I leave the library name "Standard" they copy just fine between any document and work but I'm not able to protect them with a password with that library name. if I put the same exact macro code in a library with any other name than "Standard" I get errors and the macro does not run. Steps to Reproduce: 1. Write an advanced macro. The one this is happening with pushes code and plays windows midi sounds when a cell in column A is double clicked. Place the original macro code in the Standard Library. 2. Copy the code of that macro. 3. Create a new library with a custom name and paste the macro code in to it then try to run the macro. Actual Results: When I place the same exact, 100% identical macro code in to a library with any other name than the default "Standard" library that cannot be password protected so I can protect the macros with a password the macros won't run and produce error after error that don't make any sense (to me). If I paste the same macro code in to a "Standard" library it works just fine no matter how many new sheets I use the same macro in. It's when I use a different name other than "Standard" for the macro library that the macros error and won't run. Expected Results: Copied or imported macros run regardless of the name of the library. I'm trying to do this so I can password protect the passwords so itchy fingers can't attempt editing them and messing them up causing them to not work. This sheet is going to be shared with a lot of people. I don't and can't trust all of them to leave the macro code alone. Reproducible: Always User Profile Reset: Yes OpenGL enabled: Yes Additional Info: Ran the macro's without error as it does if I don't put them in a custom named library. Version: 7.1.4.2 (x64) / LibreOffice Community Build ID: a529a4fab45b75fefc5b6226684193eb000654f6 CPU threads: 4; OS: Windows 10.0 Build 19041; UI render: Skia/Vulkan; VCL: win Locale: en-US (en_US); UI: en-US Calc: threaded
Please attach a sample document with such failing macros, to allow reproducing the problem. Thank you!
Created attachment 173498 [details] ods that works Open the ods named FileThatWorks.ods and double click on any cell in column A. That's what's supposed to happen.
Created attachment 173499 [details] ods that does not work Then open this file and click on any cell in column A. Then try to run the MidiEditor > onDoubleClickCell or any other macro. Compare the macro code. They're 100% identical. The only difference is the library name the macro is in and the size of the column widths.
This is not a bug. The two methods of running the macro are completely different. onDblClickCell is declared like this: Function onDblClickCell(oEvent As Variant) As Boolean And indeed, it expects an argument (event object), because it's an event handler. When you run functions/subs from Tools->Macros->Run Macro, or from IDE, you simply start the function, without passing any arguments to it (unlike what happens when the application calls your macro assigned to an event). This naturally complains about missing non-optional argument. Just try assigning the macro to the same sheet event as in your "FileThatWorks", and compare the two identically arranged tests - that works here using Version: 7.1.5.1 (x64) / LibreOffice Community Build ID: 2ca94649fd6dbdcab938c55c28b6a950a9634a34 CPU threads: 12; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win Locale: ru-RU (ru_RU); UI: en-US Calc: threaded and also using Version: 7.1.0.3 (x64) / LibreOffice Community Build ID: f6099ecf3d29644b5008cc8f48f42f4a40986e4c CPU threads: 12; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win Locale: ru-RU (ru_RU); UI: en-US Calc: CL
I have copied them exactly from one sheet to the other. Have you tried using a different library name than "Standard" so it can be password protected? Of course they work if the library is left named "Standard". As I indicated the problem appears when the macro codes are copy/pasted to a new library name so it can be password protected.
Created attachment 173516 [details] Screen cast of working macros in a non-Standard library (In reply to bort1352 from comment #5) > Have you tried using a different library name than "Standard" so it can be > password protected? Yes I have - using your file DOES_NOT_WORK.ods, that has an *empty* Standard library, and where the only library having the code was MidiWriter. And have *you* read what I wrote?
Yes I've read what you've written. "Just try assigning the macro to the same sheet event" If that doesn't mean copy the code exactly to the new library I'm not aware of what it means. That's exactly what I've done several times is create a new library and copy the macro code to it, save it, and it errors. If I knew what I was doing with this stuff and knew all the lingo and terms I wouldn't be asking for help with it... What do you mean by "assign the macro to the same sheet event"?
(In reply to bort1352 from comment #7) > What do you mean by "assign the macro to the same sheet event"? I even made a screen cast - attachment 173516 [details]! It shows you how it works; let me now describe you what you see. Initially you see me opening your "FileThatWorks.ods". I enable macros, then I right-click on the sheet's tab in the bottom, and in the context menu I choose "Sheet Events" (I would expect that as we are talking about "assigning macros to sheet events", you would see that it maybe relates to the topic). In the opened events dialog, I show how this file *already* has the macro "Standard.MidiEditor.onDblClickCell" assigned to "Double click" event. Then I demonstrate that in this file, double-clicking cells in column A produces edits in D3; and then I show that in the same file, trying to run the macro from *Standard* library *directly* does not work, and fails with "wrong number of parameters" error! Then you see how I open the other file ("DOES_NOT_WORK.ods") that you attached here. After accepting macros, I again right-click on the tab, and show that this file did not have events assigned to the double-click event; but I then assign it right here - and I use the macro inside the "MidiWriter" library - obviously this name is not "Standard". After assigning the macro to the event and closing the dialog (that is what I suggested you to do!), I show you that now double-clicking the cells in column A also works as expected *in this your file*, producing edits in D3. After that, I demonstrate that trying to run the macro directly still doesn't work from Run Macro dialog (as expected). And after that, I open Basic IDE, to show you that in this file, the Standard library is empty, and MidiWriter library has all the code.
Thanks!! You're right, it does work doing it that way. I didn't think it was really a bug either I was leaning toward it being something I was doing incorrectly or not doing and that's what it was. Thanks!