Thank you for that suggestion. I ran it, and it works pretty much just like the one I came up with last night, using the MouseClickHandle Event. I’ll post mine below, hopefully it will help someone else in the future. But essentially both solutions resolve issues 1 and 3. As far as #2 is concerned, I am thinking that if it will not be possible to be resolved, then maybe I can define a keyboard event which will watch for “ctrl-z” and ignore it.
Nevertheless, I took yours, and I adjusted it slightly. When you use it as such, and click just on one cell, you’ll see that the event fires up four times for each click. I’d love to understand the reasoning behind this.
Sub Test(oEvent)
Dim BackColor As Variant
Dim Sheet As Object
Dim Rows As Object
Dim Columns As Object
Dim CellRangeAddress As New com.sun.star.table.CellRangeAddress
Dim i As Byte
If Not oEvent.supportsService("com.sun.star.sheet.SheetCellRange") Then Exit Sub
Const cRed = 230
Const cGreen = 230
Const cBlue = 230
BackColor = RGB(cRed, cGreen, cBlue)
Sheet = oEvent.getSpreadsheet()
CellRangeAddress = oEvent.RangeAddress
Rows = oEvent.Rows
Columns = Sheet.getCellRangeByPosition( _
CellRangeAddress.StartColumn, 0, _
CellRangeAddress.EndColumn, Sheet.Rows.Count -1 _
)
'Nuke back background colors
Sheet.cellBackColor = -1
'Set new background colors
Rows.CellBackColor = BackColor
Columns.cellBackColor = BackColor
Do
If Sheet.getCellByPosition(0,i).String = "" Then
Sheet.getCellByPosition(0,i).String = "Event Fired " & i+1
Exit Do
Else
i = i + 1
End If
Loop
End Sub
This is the one I have come up with, with very similar results. Actually, maybe a little bit less jittery, as there aren’t as many events firing up. As far as critique is concerned, I am here to learn. Therefore, any suggestions/corrections/advise is truly appreciated . Again, this works with the MouseClickHandler:
Sub Test2(oEvent)
Const cRed = 230
Const cGreen = 230
Const cBlue = 230
Dim oDoc As Object
Dim oSheet As Object
Dim oSelection As Object
Dim vBackgroundColor As Variant
oDoc = ThisComponent
oSheet = oDoc.Sheets(0)
vBackgroundColor = RGB(cRed, cGreen, cBlue)
oSheet.cellBackColor = -1
If oDoc.CurrentSelection.Rows.Count > 1 Then
oSelection = oSheet.getCellRangeByName(split(split(oDoc.CurrentSelection.AbsoluteName,":")(0),".")(1))
Else
oSelection = oDoc.currentSelection
End If
with oSelection
.Rows.cellBackColor = vBackgroundColor
.getSpreadsheet.getCellRangeByPosition(.CellAddress.Column,0,.CellAddress.Column,.getSpreadsheet.Rows.Count -1).cellBackColor = vBackgroundColor
End With
End Sub