Difficulty navigating calc macro documentation

My specific problem right now is “How do I write a macro to apply a name to cell?”

But the thing I really want help with is how to work out the answer to questions like these from the documentation for myself.

Of course, the first thing I did was to “record macro” whilst performing the action. That doesn’t give me working code but it does at least give me a rem which suggests that “.uno:AddName” might be a clue, so I guess at some code:

fnDispatch("GoToCell", array("ToPoint", "A1")
fnDispatch("AddName", array("AddName", "foo"))

That doesn’t work, so my next stop is Google. I Google various things like:

  • LibreOffice calc macro AddName
  • OpenOffice calc macro AddName
  • AddName UNO

But without turning up anything useful.

Next I go to http://api.libreoffice.org/docs/common/ref/com/sun/star/table/module-ix.html and do some trawling. I find things like getCellRangeByName() which can use named ranges but I fail to find anything to set the range.

So, whilst an answer about how to create a named range would be very useful, what I really want to know is how could I find the functionality in the documentation for myself?

Many thanks

Andrew

Try reading a book Andrew Pitonyak.

Then download the SDK and install MRI.
If MRI is properly configured, a link to the documentation required at the moment open very quickly.

I have gone off to read Andrew Pitonyak’s document. I may be some time…

I hope you start from chapter “6.19. Select a named range” :wink:

Reading Andrew Pitonyak was a good answer. Right at the beginning it taught me about the debug stuff that is built in. I’m part-way through reading it cover-to cover but I also jumped ahead as you suggested and found reference to ThisComponent.NamedRange and addNewByName. A little bit of googling and now I have:

Dim oRanges    ' All named ranges.
oRanges = ThisComponent.NamedRanges

Dim oCellAddress As new com.sun.star.table.CellAddress
oCellAddress.Sheet = 0     'The first sheet.
oCellAddress.Column = 0    'Column A.
oCellAddress.Row = 0       'Row 1.

oRanges.addNewByName("MyName", "Sheet1.A1", oCellAddress, 0)

It helps when you realise that a range is a property of a sheet, not a cell.

The functionality is documented here: http://api.libreoffice.org/docs/common/ref/com/sun/star/sheet/XNamedRanges.html

Which I found through the main index here: http://api.libreoffice.org/docs/common/ref/index-files/index-1.html

But I must be missing a clue somewhere. Why is “ThisComponent” not listed in the index?

Many thanks

Andrew

ThisComponent in Help