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.
我该怎么办? 感谢。
答案 0 :(得分:0)
使用XFunctionAccess的6.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