Sheet Events - Event Structure

I’m trying to use the “Content Changed” Sheet Event to run a macro.

Is the event structure for the macro input variables specified anywhere? I can’t seem to find any documentation for it. i.e. in the code example below, where can I see what properties I should expect oEvent to have?

Semi-related, but is there a way to check if the macro input event has a certain property? I have a macro that looks like this for the “Content Changed” sheet event:

Sub SheetChange(oEvent)
	MsgBox "Row: " &  oEvent.CellAddress.Row
End Sub

And this works as expected if content in a single cell is modified, but if I copy a row and paste it over a different row, the macro throws an error saying that the “CellAddress” property doesn’t exist. How can I check for this before trying to access a sub-property on it?

I have no answers, sorry. But when applied to multiple cells at once this macro might need to reference a named Range in calc or a properties array- ie CellRangeAddress rather than a CellAddress ???

cell = sheet.getCellRangeByName("A1")

goodluck:)
(!LuvULibre!)

edit: maybe some part of this posted code (dont have the link atm) might help define the range…

Sub Addmultipleseriesincalcchartusingmacros

Dim Doc As Object, Sheet As Object, charts As Object
Dim Rect As new com.sun.star.awt.Rectangle
Dim Source(1) As New com.sun.star.table.CellRangeAddress	

Doc = ThisComponent
Sheet = Doc.Sheets

Rect.X = 0					' position x sur la feuille
Rect.Y = 5000				' position y sur la feuille
Rect.Width = 15000
Rect.Height = 7500

charts=Doc.Sheets.getByName("Feuille1").Charts 
for i = 0 to 0 step 2
	'selection of X data
    Source(i).Sheet = 0
    Source(i).StartColumn = 0 + 2*i
    Source(i).StartRow = 5 
    Source(i).EndColumn = 0 + 2*i
    Source(i).EndRow = 9
    'selection of y data
	Source(i + 1).Sheet = 0
    Source(i + 1).StartColumn = 1 + 2 * i
    Source(i + 1).StartRow = 5 
    Source(i + 1).EndColumn = 1 + 2 * i
    Source(i + 1).EndRow = 9	   
next i
 
charts.addNewByName("DataGraph", Rect ,Source(), false, false)
    
'place le graphique dans la feuille

Install the XrayTool (and load it into the memory by a code or manually).

Then you will able to examine the existing properties and methods of the programming objects.
Just use this line in your code:

xray oEvent

When event is call, if source is a cell you get a ScCellObj, this object have property CellAddress but, if source is a range (row is a range), you get a ScCellRangeObj, this object haven’t property CellAddress, you need property RangeAddress.

https://wiki.documentfoundation.org/Macros/Basic/Calc/Ranges

1 Like

In addition to the answer of a colleague.
You can use the following function, which in our case will return 1, 2, 3.

' lang:en
' Returns the type of the oRange object.
' Return codes:
' 1 one cell (the "com.sun.star.sheet.SheetCell" interface is supported).
' 2 rectangular range of cells (the "com.sun.star.sheet.SheetCellRange" interface is supported).
' 3 multiple rectangular cell ranges (the "com.sun.star.sheet.SheetCellRanges" interface is supported).
' 0 none of the above.
Function Range_Type(Byval oRange) As Long
  Range_Type=0
  On Error GoTo ErrLabel
  If oRange.supportsService("com.sun.star.sheet.SheetCell") Then
    Range_Type=1
  ElseIf oRange.supportsService("com.sun.star.sheet.SheetCellRanges") Then  
    Range_Type=3
  ElseIf oRange.supportsService("com.sun.star.sheet.SheetCellRange") Then
    Range_Type=2
  End If
ErrLabel:
End Function
1 Like