Loadcomponentfromurl opens file but assigned macro won't run

I am trying to create a Writer menu item that has a variety of .ott files to choose from. I am trying this way because I want to open templates only using keyboard shortcuts. The standard templates interface doesn’t provide a way to use keyboard shortcuts but menus do.

I created macros that will open documents, created a new menu item, added my macros to the list, and gave them all shortcut keys using the tilde ~ in front of the letter I want to use.

Unfortunately, the code I use opens the template as new okay, but the macro in the document won’t run. If I open the template directly from a file manager it runs with the macro perfectly. I tried a variety of my templates that have macros that run on opening, but none of them work either.

Here is my macro code, I tried simpler versions that worked just the same, but this one includes the property to run the macro:

sub Memo    
    FileName = "F:\Home\Libre\Forms\memo.ott"
    Dim  url
    url = ConvertToURL(FileName)
    Dim FileProperties(1) As New com.sun.star.beans.PropertyValue
        FileProperties(0).Name = "AsTemplate"
	    FileProperties(0).Value = True
	    FileProperties(1).Name = "MacroExecMode"
	    FileProperties(1).Value = 4
    StarDesktop.loadComponentFromURL(url,"_blank",0,FileProperties())
End Sub

As I said, that opened the file, but the file was opened in some way that ignored the macro that is supposed to run on the event of “New Document”. I assume it is actually inserting the contents of the file into a new document instead of actually opening the ott file. But I could be all wrong.

Here’s what the menu item looks like:

I have spent over 20 hours trying to make this work. Lots of research, learned a lot, but unsuccessful in my effort. Hope you can help, thanks in advance for even reading this.

SOLVED:

If a document is opened directly from a file manager – any macros assigned to “Libre/Menu/Customize/Events/New Document” will run whether they are within the document itself or in “My Macros”.

If a document is opened by a macro – macros assigned to “Libre/Menu/Customize/Events/New Document” will only run if they are assigned from “My Macros”.

So, I just copied my document’s macro from the document itself to the more general “My Macros” section. Now I am a very happy person and celebrated with four cups of strong coffee~!

A much simpler script now works to open a document template from my customized LibreOffice menu and have my macro run on opening:

sub Memo
    FileName = "C:\Users\Tech\Desktop 3\memo tests\memo.ott"
    Dim Dummy() 'An (empty) array of PropertyValues
    StarDesktop.loadComponentFromURL(ConvertToURL(FileName), "_blank", 0, Dummy)
end sub

Amazing how simply writing out the problem in a way someone else might understand, then giving it a day to think about can resolve an issue (the issue being my frustration).