Macro not starting in calc doc when created from base macro [Solved]

In Base I create a calc-sheet with the following code

	Dim oHidden(0) As New com.sun.star.beans.PropertyValue
	oHidden(0).Name = "Hidden"
	oHidden(0).Value = FALSE 
	oDBDoc=StarDesktop.loadComponentFromURL("file:///home/Affarssystem/Report/Statusreport.ots", "_blank", 0, oHidden())
	sheet=oDBDoc.sheets.getByIndex(0)
        sheet.getCellByPosition(1,0).String="Statusreport "
       Dim Props()
       PathDoc = ConvertToURL("file:///home/prm/Affarssystem/Statustest.ods")
       oDBDoc.storeAsURL(PathDoc, Props())

Statusreport.ots is an empty file except for one button connected to a macro that email a pdf-copy of the calc-sheet to a recipent.
After I edit in some comments in the calc-sheet I push the button in order to email the pdf-copy but the macro never activates. If I close the document and reopen it everything works like a charm and the macro emails the pdf-copy.

Tried with oDBDoc.release() but only get Basic runtime error.
Do someone smarter than me understand what’s preventing running a macro in the calc-sheet until you close and reopen.

I seem to remember that when opening by code the macros are disabled. So, you have to tell it to activate them.

args(0).Name = "MacroExecutionMode"
args(0).Value = 4

https://wiki.documentfoundation.org/Macros/Basic/Documents#Open_documents

Thank’s a lot elmau! I just found the same solution at

https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/StarDesktop

Tested and working great.