I am trying to write a Delphi program that will open an ODT document and execute a macro that is located in this document.
I am using the following code:
Code: Select all
[...]
var
FLibreOfficeManager, FLibreOfficeDesktop, FDocument, LParameters, LScriptProvider, LScript: OleVariant;
begin
[...]
FLibreOfficeManager := CreateOleObject('com.sun.star.ServiceManager');
FLibreOfficeDesktop := FLibreOfficeManager.createInstance('com.sun.star.frame.Desktop');
LParameters := VarArrayCreate([0, -1], varVariant);
FDocument := FLibreOfficeDesktop.LoadComponentFromURL('file:///C:/temp/Test.odt', '_blank', 0, LParameters);
LScriptProvider := FDocument.getScriptProvider;
LScript := LScriptProvider.getScript('vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document');
[...]
end;
I also tried the same using VBA in Excel:Method 'getScript' not supported by automation object
Code: Select all
Sub Main()
Dim ServiceManager As Object
Dim StarDesktop As Object
Dim Doc As Object
Dim Url As String
Dim Dummy() 'An (empty) array of PropertyValues
Dim ScriptProvider As Object
Dim Script As Object
Url = "file:///C:/temp/Test.odt"
Set ServiceManager = CreateObject("com.sun.star.ServiceManager")
Set StarDesktop = ServiceManager.CreateInstance("com.sun.star.frame.Desktop")
Set Doc = StarDesktop.loadComponentFromURL(Url, "_blank", 0, Dummy)
Set ScriptProvider = Doc.getScriptProvider
Set Script = ScriptProvider.getScript("vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document")
[...]
End Sub
So I think Delphi 2010 is not the Culprit.Runtime Error '438': Object does not support this property or method
But, when I write a Basic macro in OpenOffice like the following, everything works fine.
Code: Select all
Sub Main
Dim Doc As Object
Dim Url As String
Dim Dummy() 'An (empty) array of PropertyValues
Dim SciptProvider As Object
Dim Script As Object
Url = "file:///C:/temp/Test.odt"
Doc = StarDesktop.loadComponentFromURL(Url, "_blank", 0, Dummy)
ScriptProvider = Doc.getScriptProvider
Script = ScriptProvider.getScript("vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document")
[...]
End Sub
Code: Select all
[...]
LMasterScriptProvider := FLibreOfficeManager.CreateInstance('com.sun.star.script.provider.MasterScriptProviderFactory');
LScriptProvider := LMasterScriptProvider.CreateScriptProvider();
LScript := LScriptProvider.GetScript("vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document");
[...]
So please, do you have any idea why the method "getScript()" is not found when using the ScriptProvider of a document? Or as a workaround how one can call a script located in a document using the MasterScriptProvider like in the last code example?
PS: I also already tested opening the document using the MacroExecutionMode "ALWAYS_EXECUTE_NO_WARN". However the method still can not be found.