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

Creating a macro - Writing a Script - Using the API

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

Postby jfw » Mon Feb 04, 2008 4:03 pm

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.
jfw
 
Posts: 5
Joined: Fri Feb 01, 2008 3:31 pm

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

Postby kingfisher » Tue Feb 05, 2008 2:56 am

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   Expand viewCollapse view
oDoc.CurrentController.select( oCell )
oDummy = oDoc.createInstance( "com.sun.star.sheet.SheetCellRanges" )
oDoc.CurrentController.Select( oDummy )
Apache OpenOffice 4.1.6 on PCLinuxOS
User avatar
kingfisher
Volunteer
 
Posts: 2120
Joined: Tue Nov 20, 2007 10:53 am

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

Postby TerryE » Tue Feb 05, 2008 12:27 pm

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   Expand viewCollapse view
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.
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.
TerryE
Volunteer
 
Posts: 1402
Joined: Sat Oct 06, 2007 10:13 pm
Location: UK


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests