I have a macro that consists of adding the cell values according to their background color. But the file in particular, when opening it gives me the following error.
BASIC error, object variable not set
It should be said that the macro works correctly, I only get the error when opening the file, but it is tedious since it jumps 5/6 times from accepting each time I open the file.
I leave you the code of the macro below.
Function SUMARCOLOR(CeldaColor As String, RangoSuma As String) As Double
Dim oRango As Object
Dim oCelda As Double
Dim c As Integer
Dim f As Integer
Dim oCuenta as DOUBLE
oCuenta = 0
oRango = ThisComponent.CurrentController.ActiveSheet
oCelda = oRango.GetCellRangeByName(CeldaColor).CellBackColor
oRango = oRango.GetCellRangeByName(RangoSuma)
For c = 0 to oRango.Columns.Count - 1
For f = 0 to oRango.Rows.Count - 1
If oRango.GetCellByPosition(c,f).CellBackColor = oCelda Then
oCuenta = oCuenta+ oRango.GetCellByPosition(c,f).value
End If
Next
Next
SUMARCOLOR = oCuenta
End Function
The problem is here:
When I open it, there is no
ActiveSheet
. Instead, it should be like this: