| View previous topic :: View next topic |
| Author |
Message |
re20876 General User

Joined: 01 Jan 2007 Posts: 6
|
Posted: Thu Oct 15, 2009 11:20 am Post subject: OO Calc Macro Example from doc not working |
|
|
Hi,
I am trying to execute the following function as a OO calc macro:
| Code: |
Function ChangeCell() as Integer
if thisComponent.supportsService("com.sun.star.sheet.SpreadsheetDocument") then
msgbox "ChangeCell: Component = Spreadsheet"
end if
Dim oSheet As Object, oCell As Object
oSheet = thisComponent.getSheets.getByName("Scratch")
oCell = oSheet.getCellRangeByName("B2")
[b]
' the two following statements are only executed when opening the spreadsheet!
oCell.SetString("NewText") ' example in doc says oCell.String(...
oCell.CellBackColor = RGB(240,44,66)
[/b]
ChangeCell = oSheet.getCellByPosition(2,2).Value
Exit Function
End Function
|
Does anyone know why the two statements marked in bold aren't exetuted when I hit Ctrl-Shift-F9? This normally recalculates the whole spreadsheet. The same problem when I change the function call in a cell.
Many thanks for your help.
golpe
I was using the doc from:
http://docs.sun.com/app/docs/doc/819-1326/faail?l=de&a=view |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Thu Oct 15, 2009 1:39 pm Post subject: |
|
|
A user defined function cannot change any cell except the calling one on the same sheet. I changed your function as follows and put it in another sheet. My code assumes you would normally put it in A1 of sheet Scratch. | Code: | Function ChangeCell() as Integer
if thisComponent.supportsService("com.sun.star.sheet.SpreadsheetDocument") then
msgbox "ChangeCell: Component = Spreadsheet"
end if
Dim oSheet As Object, oCell As Object
oSheet = thisComponent.getSheets.getByName("Scratch")
oCell = oSheet.getCellRangeByName("B2")
oCell.SetString("NewText")
oCell.CellBackColor = RGB(240,44,66)
v = oSheet.getCellByPosition(2,2).Value
oCell = oSheet.GetCellRangeByName("A1")
oCell.Value = v
ChangeCell = v
End Function |
|
|
| Back to top |
|
 |
re20876 General User

Joined: 01 Jan 2007 Posts: 6
|
Posted: Fri Oct 16, 2009 1:49 am Post subject: but setting string does not work |
|
|
Hi,
many thanks for the correction. That also means that the two following statements are useless and do not work (is that right?)
| Code: |
oCell.SetString("NewText")
oCell.CellBackColor = RGB(240,44,66)
|
Many thanks
golpe (re20876)  |
|
| Back to top |
|
 |
|