Cells(r,c) reference in macro

I am totally new to LibreOffice macro’s and wanted to fill or read a cell from my active spreadsheet.
I hoped that:

Cells(1,1) = 1

would assign the value 1 to $A$1

However I get
BASIC runtime error.
Sub-procedure or function procedure not defined.

Please help me for this first step!

How many sheets in your spreadsheet? And in which one do you want to change the value in A1?

Hello,

one (!) solution:

Sub SetCellValue()

   dim oDoc as object
   dim oSheet as object
   dim oCell  as object
   
   oDoc   = ThisComponent.CurrentController
   oSheet = oDoc.ActiveSheet
   oCell = oSheet.getCellByPosition(0,0)
   oCell.value = 1
   
End Sub 

Note(s)

  • indexing starts using 0, hence A1 equals (0,0)
  • If you want to read, use: var = oCell.value (numeric), var = oCell.string (string), or var = oCell.formula (formula) and oCell.Type to get the content type.

You may want to use the BASIC Reference Cards

Macro tested using:

Version: 7.0.4.2, Build ID: dcf040e67528d9187c66b2379df5ea4407429775
CPU threads: 8; OS: Linux 5.3; UI render: GL; VCL: kf5
Locale: de-DE (de_DE.UTF-8); UI: de-DE, Calc: threaded

Hope that helps

Yes this works

If the answer works for you, please consider to click the check mark (:heavy_check_mark:) next to the answer. Thanks in advance …

Obviously an old thread, but I thought I may have found something really handy with these. Unfortunately, you need a microscope to read them and enlargement results in pixelation that makes the situation even worse unreadable.

Maybe I’ve missed something, just starting my morning coffee. :wink:

You are looking at some kind of thumbnail. Just click on the picture of the card and you are lead to the actual download-site for the pdf.
.
As direct link for the first card I get the following:

Figured as much, broke my “minimum two coffees before booting” rule. I was trying to open them via “Open image in new tab”, and like a noob never thought to simply try left clicking. :rofl:

Thanks for taking the time, much appreciated as these are super-handy references.