Hi I’m pretty new to LibreOffice Calc and macros, so please forgive me if this question is very dumb. However I was trying to make some functions in relation to color. However the following code just doesnt work:
Function getCellText(sAddress As String) As String
Dim oSheets As Variant
Dim oCellRangesByName As Variant
Dim oXCellRange As Variant
Dim oCellByPosition As Variant
On Error GoTo Wrong_parm
oSheets = ThisComponent.getSheets()
oCellRangesByName = oSheets.getCellRangesByName(sAddress)
oXCellRange = oCellRangesByName(0)
oCellByPosition = oXCellRange.getCellByPosition(0, 0)
getCellText = oCellByPosition.getString()
Exit Function
Wrong_parm:
getCellText = ""
End Function
sub H2D(sAddress As String)
dim oFunction as variant
oFunction = createUnoService("com.sun.star.sheet.FunctionAccess")
dim aArgument(0) as variant
dim hArgs(0)
dim result
hex = getCellText(sAddress)
aArgument(0)=hex
result = oFunction.callFunction( "HEX2DEC", aArgument())
H2D = result
end sub
The function is supposed to take the cell value as a string and return the hex value to base 10. However this returns #NAME?.
Any help is appreciated. Thanks.