Bug 143306 - Changing Macro Library name to password them = multiple errors
Summary: Changing Macro Library name to password them = multiple errors
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.1.4.2 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-12 08:05 UTC by bort1352
Modified: 2021-07-13 01:48 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
ods that works (137.41 KB, application/vnd.oasis.opendocument.spreadsheet)
2021-07-12 08:13 UTC, bort1352
Details
ods that does not work (27.00 KB, application/vnd.oasis.opendocument.spreadsheet)
2021-07-12 08:15 UTC, bort1352
Details
Screen cast of working macros in a non-Standard library (2.33 MB, image/gif)
2021-07-12 19:00 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bort1352 2021-07-12 08:05:32 UTC
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
Comment 1 Mike Kaganski 2021-07-12 08:10:12 UTC
Please attach a sample document with such failing macros, to allow reproducing the problem. Thank you!
Comment 2 bort1352 2021-07-12 08:13:02 UTC
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.
Comment 3 bort1352 2021-07-12 08:15:33 UTC
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.
Comment 4 Mike Kaganski 2021-07-12 08:41:29 UTC
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
Comment 5 bort1352 2021-07-12 18:35:32 UTC
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.
Comment 6 Mike Kaganski 2021-07-12 19:00:43 UTC
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?
Comment 7 bort1352 2021-07-12 19:11:01 UTC
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"?
Comment 8 Mike Kaganski 2021-07-12 20:13:18 UTC
(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.
Comment 9 bort1352 2021-07-13 01:48:35 UTC
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!