Installation: LibreOffice 7.0.0.3, Win10 2004 19041.450
I get "Object variable not set" run time error when I run this code. In the LibreOffice debugger I can see the 2-D array with values properly. I am not able to access individual values inside the array. What am I doing wrong?
Function Test()
Dim objPlay As Object
Dim arrTable(1, 1) As String, strValue As String
objPlay = ThisComponent.Sheets.getByName("Play")
arrTable = objPlay.getCellRangeByPosition(0, 0, 1, 1).getDataArray()
strValue = arrTable(0, 0)
End Function
No, in the debugger you see not a two-dimensional array, but an array of arrays - an array, each of whose elements represents an array of values for one row of the range.
In the description of the getDataArray method, this is called sequence< sequence< any > >
Just repeat the syntax for accessing the desired element from the debugger window:
Function Test
Dim objPlay As Object
Dim arrTable As Variant
Dim strValue As String
objPlay = ThisComponent.getSheets().getByName("Play")
arrTable = objPlay.getCellRangeByPosition(0, 0, 1, 1).getDataArray()
strValue = arrTable(0)(0)
Rem And don't forget to return the function result
Test = strValue
End Function