Run document macros via API if Desktop is hidden
Posted: Fri Jul 02, 2010 9:08 pm
I would like to run macro (written with star basic) via API. Macros is stored in document. API is called from IBM Lotus Notes lotus script.
The problem is that operation is performed in backgorund (document must not be visible), but ExecuteDispatch does not work in that case (there is no any changes in test2.ods). As for GetScriptProvider().getScript(ScriptURI$), it returns an error “Instance member GETSCRIPT does not exist”.
Please, give me a clue how to run macro from document.
1.ExecuteDispatch, document is visible
2.ExecuteDispatch, document is not visible.
The code is almost the same. Changes in property value
3.GetScriptProvider().getScript(ScriptURI$)
Document – it is default Calc document. Macros was created with Tools – Macros – Macros... Selecet Untitled – Standard – New. Name is “Module1”.
The problem is that operation is performed in backgorund (document must not be visible), but ExecuteDispatch does not work in that case (there is no any changes in test2.ods). As for GetScriptProvider().getScript(ScriptURI$), it returns an error “Instance member GETSCRIPT does not exist”.
Please, give me a clue how to run macro from document.
1.ExecuteDispatch, document is visible
Code: Select all
Set OOServiceManager = CreateObject("com.sun.star.ServiceManager")
Set OODispatcher = OOServiceManager.CreateInstance("com.sun.star.frame.DispatchHelper")
Set OODesktop = OOServiceManager.CreateInstance("com.sun.star.frame.Desktop")
MacroName$ = {standard.module1.test}
ReDim args(1)
Set PropertyValue = OOServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
PropertyValue.Name = "MacroExecutionMode"
PropertyValue.Value = 4
Set args(0) = PropertyValue
PropertyValue.Name = "Hidden"
PropertyValue.Value = False
Set args(1) = PropertyValue
Set OOSpreadSheet = OODesktop.loadComponentFromURL("file:///d:\test.ods", "_default", 0, args)
ReDim args(0)
Set PropertyValue = OOServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
PropertyValue.Name = ""
PropertyValue.Value = ""
Set args(0) = PropertyValue
Call OODispatcher.ExecuteDispatch(OOSpreadSheet.CurrentController.Frame, "macro://./" & MacroName, "", 0, args)
ReDim args(0)
PropertyValue.Name = "Overwrite"
PropertyValue.Value = True
Set args(0) = PropertyValue
Call OOSpreadSheet.StoreToURL("file:///d:/test2.ods", args())
Call OOSpreadSheet.Close(False)
The code is almost the same. Changes in property value
Code: Select all
ReDim args(1)
Set PropertyValue = OOServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
PropertyValue.Name = "MacroExecutionMode"
PropertyValue.Value = 4
Set args(0) = PropertyValue
PropertyValue.Name = "Hidden"
[b]PropertyValue.Value = True[/b]
Set args(1) = PropertyValue
3.GetScriptProvider().getScript(ScriptURI$)
Code: Select all
Set OOScriptProvider= OOSpreadSheet.GetScriptProvider()
Set OOScript = OOScriptProvider.getScript("")
Call OOScript.invoke(aa, aa, aa)
Code: Select all
Sub test
ThisComponent.Sheets.GetByIndex(0).getCellByPosition(2, 2).SetString("OK1")
End Sub