OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

OO Calc Macro Example from doc not working

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
re20876
General User
General User


Joined: 01 Jan 2007
Posts: 6

PostPosted: Thu Oct 15, 2009 11:20 am    Post subject: OO Calc Macro Example from doc not working Reply with quote

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
View user's profile Send private message Yahoo Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Thu Oct 15, 2009 1:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
re20876
General User
General User


Joined: 01 Jan 2007
Posts: 6

PostPosted: Fri Oct 16, 2009 1:49 am    Post subject: but setting string does not work Reply with quote

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) Very Happy
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group