# How can I get the coordinates of the OnFocused Cell?

sub main()

Dim Current_Sheet As String
oSheet = ThisComponent.CurrentController.ActiveSheet
oActiveCell = ThisComponent.getCurrentSelection


end sub

In multiple cell selection, when the selected cells are A1:C3 and the cell C3 is active(OnFocus), then

[RangeAddress] - StartRow: 0, StartColumn: 0, EndRow: 2, EndColumn 2.

But I only want to know the coordinates of the active cell(in this case, "C3") that I clicked first.

How can I get it?

edit retag close merge delete

Sorry. Just found that you had posted this question again as a duplicate. What good for? Would you mind to read about forum manners?

( 2017-04-17 18:59:27 +0200 )edit

I'm so sorry. I don't know well how to use this site yet. It seems so slow. And I'm still learning. I shall be careful hereafter.

( 2017-04-17 20:43:54 +0200 )edit

Sorry. I was too harsh. Anyway I would like to know if my example was helpful, and also for what purpose the knowledge about ActiveCell position is needed.
It's not a new fact that Calc does not support this generously, and after all most users, even those who sometimes write some lines of code, get along with things as they are.

( 2017-04-17 21:07:22 +0200 )edit

Sort by » oldest newest most voted

(I hadn't noticed this as a duplicate in time. Thus I suspected the askbot to have killed my previous answer. Having added an attachment here, I will not delete this answer despite the fact that posting duplicates should not be encouraged.)

The ActiveCell does not occur in the LibreOffice (Calc) API as a concept. It does exist in a sense like "the cell that will be edited if F2 is pressed or if the formula bar is entered" or "the cell that has an emphasizing border in the view". However, this cell is not assured to be in the CurrentSelection, and if it is, it may not be the topmost leftmost of any one of the single ranges contained therein.
Moreover the CurrentSelection can be multirange, and then not supporting the service "com.sun.star.sheet.SheetCellRange", not to mention "com.sun.star.sheet.SheetCell".

If you urgently need to work with the ActiveCell in user code, I thus would suggest you set the Option VBAsupport 1 in LibO BASIC, and use the then as-if-predefined-variable ActiveCell.

As a matter of fact I do not know application cases for this.

How to do as I suggested you may learn from this attached example.

Editing: I did not take precautions against premature calls to the included user functions. Therefore you will get errors during the recalculation OnLoadDocument. As soon as the document is completely loaded a Ctrl+Shift+F9 will call a recalculation that should work.

more