LibreOffice Calc 宏函数访问单元格范围

LibreOffice Calc macro function accessing cell range

我有来自 的功能(在此处重复):

public function CHECKBZRANGE(vCellRangeValues as variant) as integer

    dim i as integer
    dim vCellValue as variant

    for each vCellValue in vCellRangeValues
        msgbox vCellValue
        i = i + 1
    next

    CHECKBZRANGE = i
end function

曾经在 LibreOffice <=6.x.y 中工作,例如作为 =CHECKBZRANGE(A6:C9)。现在在 LibreOffice 7.0.0.3 中我收到此错误消息

Inadmissible value or data type.
Data type mismatch.
[OK]

for each vCellValue in vCellRangeValues

我搜索过这个,但找不到答案。这是:

  1. LibreOffice 的新功能VBA?
  2. 回归?

如何访问宏函数中的范围值?

由于vCellRangeValues不是一个单元格区域,而是这些单元格的值的数组,你应该使用两个嵌套循环来显示每个值——跨越行和列:

Function CHECKBZRANGE(vCellRangeValues As Variant) As Integer 
Dim iRow As Long, iColumn As Long 
    For iRow = LBound(vCellRangeValues) To UBound(vCellRangeValues)
        For iColumn = LBound(vCellRangeValues,2) To UBound(vCellRangeValues,2)
            msgbox "Cell (" & iRow & "," & iColumn & ") = " & vCellRangeValues(iRow, iColumn )
        Next iColumn
    Next iRow
    
    CHECKBZRANGE = (UBound(vCellRangeValues)-LBound(vCellRangeValues) +1) * _
                                    (UBound(vCellRangeValues,2)-LBound(vCellRangeValues,2) +1)
End Function