Openoffice custom functions/macros

So, I "just" wanted to insert a date value into some openoffice spreadsheet, that should be derived from the documents name. I really thought, inserting a value derived from the current document's filename must be very easy.

I do a daily plan for the things I intend to do on a day, and name it "tagesplan_2008-11-22.ods".
And I want the name in this file not always be the date when I open/print the file, but the exact day it was intended for, and this is already coded into the filename.

I thought the should be easy, but it turned out to take about one and a half hour or so.
First I assumed that must be made with a macro and searched information about how to write these, maybe a simple howto or tutorial.
I didn't find an easy and clear introduction somehow.
Still, I found some examples of things similar to what I wanted to do:
And after a while, I had nearly what I wanted to do - (the example with setting a named field value still doesn't work, by the way) I needed to write a custom function.
Now, only some array stuff was missing. I tried to access the array in several ways. Even the documentation in the OpenOffice BASIC Wiki about arrays did only tell how to define empty arrays, but not how to insert values, and not how to access them!

I finally found it all out, and now I have a custom function that does what I want. And I added the Array acces etc. info into the wiki page!
In the macros for my file, I define:


Function FileNameDate
Dim oDoc,sUrl,aUrl,filename
oDoc = ThisComponent
sUrl = oDoc.getURL
If len(sUrl) = 0 then
MsgBox("File doesn'thave a name yet")
End
EndIf
aUrl= Split(sURl,"/") 'URL to array
filename = aUrl(uBound(aUrl))
Dim fileNameSplitDot
fileNameSplitDot = Split(filename, ".")
Dim fileSplitUnderScore
fileSplitUnderScore = Split(fileNameSplitDot(0), "_")
FileNameDate = fileSplitUnderScore(1)
End Function


And in my field, I just set the field's value to "=FileNameDate()"

Now, I only need to find out how to enable exactly this one macro to run without being stopped by Openoffice's security mechanism, which forbids me to run it when I reload the file :(
I have the feeling it's quite hard to write macros/custom functions because it seem not to be well documented, and has an ugly syntax...
Maybe it's easier from the syntax when you do it with python or beanshell, but then again, the documentation issue might be even worse there (I definitely wanted to do my task that way, but found even less docs)