Determining, saving & going back to range? [Range Functions]
Determining, saving & going back to range? [Range Functions]
Does anyone have the BASIC code covering the extraction of the absolute address of the current selection, so that it can be stored and passed to the uno:GoToCell command at the end of a macro - basically my macro needs to copy the selection in place when it is kicked off, then move around between sheets but eventually return to the originally highlighted range. Defining a rangename and dropping and recreating it in the macro will not work, so I'm hoping there's a simple method for getting the full address of the current range for assigning to the args for GoToCell.
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Determining, saving and going back to a range?
I believe you should be asking about this on the macros board. Assign a variable (such as oCell) to the cell, another (such as oDoc) to the document and use the following code to select the cell then deselect it while remaining at that location:
Code: Select all
oDoc.CurrentController.select( oCell )
oDummy = oDoc.createInstance( "com.sun.star.sheet.SheetCellRanges" )
oDoc.CurrentController.Select( oDummy )
Apache OpenOffice 4.1.9 on Linux
Re: Determining, saving and going back to a range?
Here are two routines which do what you want. If you are working within one macro then you could just use local variables and stick these lines inline. The advantage of using global variable is that you can split the save and restore selection into two separate macros with user interaction in between A good hint when debugging this lot is to use Xray, by including a GlobalScope.BasicLibraries.LoadLibrary( "XrayTool" ) in your code to make sure its loaDed and then put in debug 'Xray <whatever> if you want to examine the methods and properties to work out what you need.
Code: Select all
Global oSheet, oSel
Sub GetPos
oSel = ThisComponent.CurrentController.Selection
oSheet = ThisComponent.CurrentController.ActiveSheet
End Sub
Sub PutPos
ThisComponent.CurrentController.ActiveSheet = oSheet
ThisComponent.CurrentController.Select(oSheet.getCellByPosition( _
oSel.RangeAddress.EndColumn, oSel.RangeAddress.EndRow))
End Sub
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.