Customize key to a macro not allowed

I have created a macro and tested it (it runs correctly) from Tools → Macros → Run Macro

This is in Writer.

I go to Tools → Customize → Keyboard to assign the key. I have chosen Shift-F12.

When I select the key, the Modify button is enabled and I can assign any normal command to it. But when I scroll down the left hand Category column, as soon as I select the LibreOffice macros item, the Modify button goes grey, and is no longer usable. So, what is going on? All help I can find about assigning macros to keys says this is the correct procedure.

What am I overlooking, this is really maddening.

It goes to grey until you have selected a sub - as long as you are in Category and have not selected the Function (which is a sub) it is greyed.

I have gone to the stage of selecting LibreOffice Macros → My Macros → Standard → Moduke1 And then selecting my macro from the Function column. The Modify button is still grey.

I should note this is my first stab at a macro, I found it very confusing so what I have is plagiarized from some other web posting. I could not get Macro recording to do what I wanted, which is to perform a simple Find “xxx” and replace with “yyy” - all occurrences. If the macro runs from the Tools → Macro menu, is there something else to do to make it acceptable to run from the keyboard?

OK, managed to figure this out. After attempting a macro record - which didn’t do what I wanted, I found a some sample macro code on the web which I revised to my needs. Then went into Edit Macros and selected the original macro built by the record macro function. I replaced all the text with the code I found on the web.

Unfortunately I replaced ALL THE TEXT, including the two lines SUB Main / END SUB.

Without these two lines, you cannot do the keyboard assign. I added them back in and all is now well.

So just where is this requirement for SUB Main / END SUB documented?



From the LO documentation

Defining subroutines with SUB
Individual macros are stored in subroutines and these subroutines begin with the keyword SUB.
The end of a subroutine is indicated by the words END SUB.

For further reference, see Getting Started with LibreOffice, Chapter 13 - Getting Started With Macros