Disable Macro in new document, copy footer to a new document

Hi,

I need help on the following:
1st:
I have a template “.ods” that when opens runs a macro that fetch data from a database, then when finished, it’s supposed to save with a new name, closing the template without changes. This procedure works, but the problem is that when I open the created file it runs the macro… How can I disable it when saving the new file?
2nd:
How can I copy the footer and header from a document to another by macro?

Thanks,
Rui

Hi

You can use a code like this to disable the launch of the macro:

Sub DisableMacroOnNew

dim oDoc as object, oEvts as object
Dim Args(0) As New com.sun.star.beans.PropertyValue

oDoc = ThisComponent

oEvts = oDoc.getEvents()

If oEvts.hasByName("OnNew") Then
   oEvts.replaceByName("OnNew", Args())
End If

end sub

Header & Footer are part of the page style. The easiest way seems to be to load the styles of the template (or another source document) as follows:

Sub LoadStyle

dim Args(0) As New com.sun.star.beans.PropertyValue
dim oDoc as object
dim sUrl as string

Args(0).name = "LoadPageStyles" 
Args(0).value = true

oDoc = ThisComponent
sUrl = convertToUrl("c:\Test\template.ods")

if fileExists(sUrl) then
	oDoc.styleFamilies.loadStylesFromURL(sUrl, Args())
else
	msgbox "Source not found", 64, "Load styles"
end if	
end sub