The macro works fine if I run it from the macro menu or if I run it from the execute event on a button control. When I run the macro from a formula, I can hide/show a row or column, etc. but I can not update a value or change the background color. I have a message box display in the macro to verify that it runs. I have had the same results when I used a default spreadsheet and made no changes other than enter the formula "If(A2=2;CHG();"")" in A1 and then entered a 2 in A2.
I have gone through all the on-line documentation I can find which is where this macro came from. All say the same thing which is that calling a macro as a function from a formula and changing the background color is supposed to work.
Yes, I know how to apply a STYLE from conditional formatting but I am trying to avoid having to setup a STYLE for each data type and color combination I am using. If I could setup a STYLE that changed only the background color, that would work but I don't believe that can be done.
I would greatly appreciate it if someone could tell me
1) what I am doing wrong in the macro or
2) it can't be done or
3) it is a bug in OpenOffice 3 or
4) how to setup a style that only changes the background color
The macro I am using is in Basic. I don't care if the solution needs to be in UNO format, Python, BeanShell, or Java script.
Thanks in advance for any help I can get. Here is the macro:
Code: Select all
REM ***** BASIC *****
Option Explicit
Sub Main
End Sub
function CHG()
Dim oDocument As Object, oSheet As Object, oCell As Object
oDocument=ThisComponent
oSheet=oDocument.Sheets(0)
oCell=oSheet.getCellRangeByName("D2")
oCell.setValue(23658)
'oCell.NumberFormat=2 '23658.00
'oCell.SetString("oops")
'oCell.setFormula("=FUNCTION()")
oCell.IsCellBackgroundTransparent = false
oCell.CellBackColor = RGB(255,141,56)
MsgBox "out"
end function