Ask Your Question
0

How can I get the coordinates of the OnFocused Cell?

asked 2017-04-17 17:35:41 +0200

fringe0927 gravatar image

sub main()

Dim Current_Sheet As String
oSheet = ThisComponent.CurrentController.ActiveSheet    
oActiveCell = ThisComponent.getCurrentSelection
Cell_r = oActiveCell.RangeAddress.StartRow
Cell_c = oActiveCell.RangeAddress.StartColumn

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?

Thank you for your help.

edit retag flag offensive close merge delete

Comments

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

Lupp gravatar imageLupp ( 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.

fringe0927 gravatar imagefringe0927 ( 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.

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

1 Answer

Sort by » oldest newest most voted
0

answered 2017-04-17 18:36:47 +0200

Lupp gravatar image

updated 2017-04-17 18:59:22 +0200

(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.

edit flag offensive delete link more

Comments

Thanks to you, I've solved my problem completely. Thank you so much.

fringe0927 gravatar imagefringe0927 ( 2017-04-17 21:56:39 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-04-17 17:35:41 +0200

Seen: 136 times

Last updated: Apr 17 '17