Libreoffice宏观平均计算

时间:2016-11-28 04:23:23

标签: macros average libreoffice

REM ***** BASIC *****

Sub hell_world
    dim hell_world as object
    hell_world = Range("G31:G42")
    Range("H45") = WorksheetFunction.Average(hell_world)
End Sub

我有,我得到错误:

BASIC runtime error.
Sub-procedure or function procedure not defined.

我该怎么办? 感谢。

1 个答案:

答案 0 :(得分:0)

使用XFunctionAccess6.28. Use FunctionAccess to call Calc Functions中所述的Andrew Pitonyak's macro document

Sub CallAverage
    Dim oSheet, oRange, oCell, nResult, oFuncAcc
    oSheet = ThisComponent.CurrentController.ActiveSheet
    oRange = oSheet.getCellRangeByName("G31:G42")
    oCell = oSheet.getCellRangeByName("H45")
    oFuncAcc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
    nResult = oFuncAcc.callFunction("Average", Array(oRange))
    oCell.setValue(nResult)
End Sub
相关问题