Page 1 of 1

Determining, saving & going back to range? [Range Functions]

Posted: Mon Feb 04, 2008 4:03 pm
by jfw
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.

Re: Determining, saving and going back to a range?

Posted: Tue Feb 05, 2008 2:56 am
by kingfisher
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 )

Re: Determining, saving and going back to a range?

Posted: Tue Feb 05, 2008 12:27 pm
by TerryE
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

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