[Solved] Get value of named cell when sheet is unknown

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

[Solved] Get value of named cell when sheet is unknown

Post by bartjeman »

I have a named cell "kneeheight" on sheet "Order Entry" (sheet0)

A macro is called from a button on the active sheet "Drawing" (sheet1). When I use getCellRangebyName("kneeheight"), I get an error. However when I copy the button to the sheet "Order Entry" (sheet0) it works.

Is there a way to get the value of a named range that is not on the active sheet?

Thanks
Last edited by Hagar Delest on Tue Aug 14, 2012 8:30 am, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.7 on Windows 10
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

Re: get value of named cell when sheet is unknown

Post by bartjeman »

I did more googling and got this working:
KneeType = oDoc.NamedRanges.getByName("kneetype").getReferredCells.value

What would be the equivalent code if the cell contains text? I tried ".string" which does not work

Thank you.
OpenOffice 4.1.7 on Windows 10
FJCC
Moderator
Posts: 9619
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: get value of named cell when sheet is unknown

Post by FJCC »

Every cell has a String property, so that should work. This worked for me

Code: Select all

CellString = ThisComponent.NamedRanges.getByName("First").ReferredCells.String
Print CellString
What do you mean when you say it didn't work?
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
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

Re: Get value of named cell when sheet is unknown

Post by bartjeman »

Thanks FJCC
oo maros are so quirky... I noticed you used "ReferredCells" as opposed to my "getReferredCells" and both seem to work fine with

Bone head mistake, I did not think that my named range could be misspelled, but guess what, it was :oops:

Thanks
OpenOffice 4.1.7 on Windows 10
Post Reply