Property changed in LO 7.1.7.2 in comparison with 6.3.6.2

Macro with the line
iActiveColumn = oActiveCell.CellAddress.Column
works properly in LO 6.3.6.2, but in 7.1.7.2 this line generates message
Property or method not found: CellAddress.
What should I change to work with 7.1.7.2 ? Windows 10.0

Could you please upload the error demo file?

This is demo:
sub ActiveCell()
Dim oRanges, oActiveCell, oDoc
dim Cell as Object, lActiveColumn&, lActiveRow&

oDoc = ThisComponent
oRanges = oDoc.createInstance(“com.sun.star.sheet.SheetCellRanges”)
oDoc.CurrentController.Select(oRanges)
oActiveCell = oDoc.CurrentSelection 'Get the active cell
lActiveColumn = oActiveCell.CellAddress.Column
lActiveRow = oActiveCell.CellAddress.Row
Print lActiveColumn & “***” & lActiveRow

end sub

I select a group of merged cells, and this sub gives me an address of the first merged cell - exactly what I need. But LO 7 cancelled this possibility.

This happens with mindlessly copied code. If oActiveCell is not a single cell, then you can’t get a CellAddress from it. Some lines above might be oActiceCell = ThisComponent.CurrentSelection
Now you select a merged cell or some other rectangle of cells and wonder why oActiverCell is not the active cell.

Function getActiveCell(oView)
Dim as1(), lSheet&,lCol&,lRow$, sDum as String,bErr as Boolean
   as1()  = Split(oView.ViewData, ";")
   lSheet = CLng(as1(1))
   sDum = as1(lSheet +3)
   as1() = Split(sDum, "/")
   on error goto errSlash
      lCol = CLng(as1(0))
      lRow = CLng(as1(1))
   on error goto 0
   getActiveCell = oView.Model.getSheets.getByIndex(lSheet).getcellByPosition(lCol,lRow)
exit Function
errSlash:
   if NOT(bErr) then
      bErr = True
      as1() = Split(sDum, "+")
      resume
   endif
End Function

Sorry for the misunderstanding, what is oView in your function?

What is wrong in sub ActiveCell ?

sub subActiveCell()
Dim oRanges, oActiveCell, oDoc
dim oView, lC, lR

oDoc = ThisComponent
oRanges = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges")
oDoc.CurrentController.Select(oRanges)
oView = oDoc.CurrentSelection

lC = getActiveCell(oView).CellAddress.Column
lR = getActiveCell(oView).CellAddress.Row
Print lC & "***" & lR

end sub


Function getActiveCell(oView)
Dim as1(), lSheet&,lCol&,lRow$, sDum as String,bErr as Boolean
   as1()  = Split(oView.ViewData, ";")
   lSheet = CLng(as1(1))
   sDum = as1(lSheet +3)
   as1() = Split(sDum, "/")
   on error goto errSlash
      lCol = CLng(as1(0))
      lRow = CLng(as1(1))
   on error goto 0
   getActiveCell = oView.Model.getSheets.getByIndex(lSheet).getcellByPosition(lCol,lRow)
exit Function
errSlash:
   if NOT(bErr) then
      bErr = True
      as1() = Split(sDum, "+")
      resume
   endif
End Function

oView is the current controller in most cases but it could be any other controller as well. You may prefer

Function getActiveCell(Optional oView)
if isMissing(oView) then oView = ThisComponent.getCurrentController()
...

The CurrentSelection can be a single cell, a range of cells, a multiple selection of ranges or any kind of shape (comment, picture, chart, …).
My function only returns the active cell where you enter data when typing into the formula bar.

I’m ‘trying to learn to fish’ from Villeroy’s response. Is this correct: The ViewData used to create the as1() array is the return from getViewData() in the XController interface, which is implemented by the ThisComponent.getCurrentController Villeroy mentions. It’s handy that he knows what that returns! And the Model later on is the SpreadsheetDocument class (held in the CurrentController) implementing the XSpreadsheetDocument interface to return about the only thing it can, via getSheets().

[Tutorial] Introduction into object inspection with MRI

2 Likes

In the 1st line you create an abstract and absolutly empty Container for multible single Cells|Cellranges.
the 2nd line selects explizitly this nothing in
and the third line bind the nothing to oView… so oView is the same nothing

!!! please stop this coding by random copy and paste without any clue !!!

This used to be a slightly absurd method to unselect any range selection, so the active cell remains. It still works like that. It boils down the current selection to the active cell.

@Villeroy: yes youre right, the third line works, but the first 2 quoted lines makes no sense without additional code to fill ‘oRanges’

I had no other clue other than OOME Fourth Edition, Listing 462 Obtain the active cell. And it works.

But you’re the one who ask:

@karolus : The problem was: It works with 6.3.6.2 and doesn’t work with 7.1.7.2

Andrew Pitonyak code.
What’s the point of doing nothing code? This is a trick. Removing the highlight by passing the empty range collection. I have it orange-red.
NOTE: Same with .SheetCell or .SheetCellRange doesn’t work.

	With ThisComponent
		.CurrentController.select(oCell)
		oRanges = .createInstance("com.sun.star.sheet.SheetCellRanges")
		' Remove the highlight by passing the empty range collection.
		.CurrentController.select(oRanges)
	End With

BTW, everything worked and works for me.