Active cell and selection change event

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Fraz627
Posts: 22
Joined: Sat Jun 17, 2017 8:31 am

Active cell and selection change event

Post by Fraz627 »

I am converting a VBA app to run with open office. In the VBA app I had code that places the current cells row and column number in a cell for later use. The code was triggered by the sheet selection change event.

Now I have adapted the macro to run in oo but when I attach it to the sheet event selection change it give me an error when the user clicks on a non cell (menu item, column/row heading ect) as well as when the mouse is over a non cell object.

Am I asking to much?
[Sub cursor_positon

Dim oCell,oSheets,oSheet,oDoc,cellText
Dim Cell As Object
Dim oCells
dim row as integer
dim column as integer
dim oRow as integer
dim ocolumn as integer
dim tempstring as string

oController = ThisComponent.getCurrentController()

oDoc = ThisComponent
oCell = oDoc.getCurrentSelection
oSheet = oDoc.Sheets.getByName("sheet1")

iCol1= oCell.CellAddress.Column
iRow1= oCell.CellAddress.Row
oCell = oSheet.getCellrangebyname("a3") rem column number
oCell.String = iCOL1
oCell = oSheet.getCellrangebyname("b3")
oCell.String = irow1

END SUB code][/code]

I inserted the code for review.
Open Office 4.1 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Active cell and selection change event

Post by Zizi64 »

You must examine first if the oCell object IS a cell really or not:

Code: Select all

If oCell.ImplementationName = "ScCellObj" then
...
else
...
end if

Install and use the MRI or the XrayTool for study the programming objects of the office suite.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Fraz627
Posts: 22
Joined: Sat Jun 17, 2017 8:31 am

[solved] Re: Active cell and selection change event

Post by Fraz627 »

Thanks that did it.

Youre a real help
Thanks
Open Office 4.1 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Active cell and selection change event

Post by Villeroy »

Unfortunately, there is no direct API function to get the active cell. If you search this forum for "getActiveCell" you will find a user defined Basic function which reads the active cells position from a "ViewData" string.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply