Macros Libreoffice宏平均值计算

Macros Libreoffice宏平均值计算,macros,average,libreoffice,Macros,Average,Libreoffice,REM******基础***** 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. 我该怎么办?

REM******基础*****

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.
我该怎么办? 谢谢。

按照
6.28中的说明使用。使用FunctionAccess调用的计算函数

次平均值
暗淡的oSheet、橙色、oCell、nResult、OfUnacc
oSheet=ThisComponent.CurrentController.ActiveSheet
橙色=oSheet.getCellRangeByName(“G31:G42”)
oCell=oSheet.getCellRangeByName(“H45”)
Ofuncac=CreateUnoService(“com.sun.star.sheet.FunctionAccess”)
nResult=Ofuncac.callFunction(“平均”,数组(橙色))
oCell.setValue(nResult)
端接头

我得到一个错误:基本运行时错误。未找到属性或方法:ActiveSheet。请确保从计算电子表格运行宏,而不是从基本窗口或编写器运行宏。另一个选项是这样写:
oSheet=ThisComponent.Sheets(0)
。但同样,这只在
ThisComponent
是电子表格时才起作用。