Calc macro equivalent of VBA Range("...")

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
polczynskim
Posts: 1
Joined: Wed Jul 01, 2015 1:31 pm

Calc macro equivalent of VBA Range("...")

Post by polczynskim »

I am totally new to OpenOffice macros, but have some experience with Excel VBA. What is the OpenOffice macro equivalent of this VBA statement to read the contents of a spreadsheet cell named "ABC"?

x = Range("ABC")

Also, what is the equivalent of this statement to read the contents of cell 1,1?

x = Cells(1,1)

Thanks for helping newbie!
Apache OpenOffice 4.1.1 - Windows 8
FJCC
Moderator
Posts: 9638
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Calc macro equivalent of VBA Range("...")

Post by FJCC »

To answer your two specific questions

Code: Select all

oSheet = ThisComponent.Sheets.getByName("Sheet1")
x= oSheet.getCellRangeByName("ABC")
y= oSheet.getCellByPosition(Column, Row)
There is a lot of good macro information at http://www.pitonyak.org/oo.php. There are also object inspectors call XRay and MRI, and you should get one of them if you want to write macros.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Zizi64
Volunteer
Posts: 11508
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Calc macro equivalent of VBA Range("...")

Post by Zizi64 »

What is the OpenOffice macro equivalent of this VBA statement to read the contents of a spreadsheet cell named "ABC"?
The NAMED cell(range) and the Absolut name of a cell is not equivalent. For example: $A$1 is an absolut name, but "ABC" is an user defined name of a specific cell.

Code: Select all

	
 oDoc = ThisComponent ' get the actual document object
 oRange = oDoc.NamedRanges.getByName("ABC") ' get a global named range object from the document
 oCell = oRange.ReferredCells.getCellByPosition(0,0)	' get the top-left cell object from the named range
 floatMyValue = oCell.Value
 'stringMyString = oCell.String
 'stringMyFormula = oCell.Formula
 'stringMyFormulaLocal = oCell.FormulaLocal
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.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.
Post Reply