Page 1 of 1

[Solved] Insert formula with quotation marks into cell

Posted: Tue Dec 17, 2019 10:40 pm
by MATT.B
im having a bit of trouble with this bit of code
the objective is to use a macro to merger cells AG22-AH22 (COMPLETED) but when i try to put the formula "=CELL("CONTENTS";$PAGE_4.AC18)" into a cell i get an error about parenthesis. i even tried something like the below code but got a syntax error

Code: Select all

oCells = oSheet.getCellrangeByname("AG22:AH22")
	oCell = oSheet.getCellRangeByName("AG22")
	oCells.merge(True)
	oCell.setformula("=CELL("CONTENTS";$PAGE_4.AC18)")
i also tried

Code: Select all

oCells = oSheet.getCellrangeByname("AG22:AH22")
	oCell = oSheet.getCellRangeByName("AG22")
	oCells.merge(True)
	myformula = "=CELL("CONTENTS";$PAGE_4.AC18)"
        oCell.setformula(myformula)
not sure what i did wrong in this

Re: Trying to insert formula into cell with macro

Posted: Tue Dec 17, 2019 11:13 pm
by FJCC
The quotation marks inside of your formula are causing the problem. Try

Code: Select all

 oCell.setformula("=CELL(""CONTENTS"";$PAGE_4.AC18)")

Re: [Solved] Insert formula with quotation marks into cell

Posted: Fri Dec 01, 2023 7:28 pm
by Rotnbair
Thanks, oCell.setformula() is exactly what I needed! Via a forum seaerch I am nearly always able to find things like this, including locating the Active Cell with

oCell = oSheet.getCellByPosition(ACcol,ACrow)

Is there a manual somewhere that contains all the oCell & oSheet structures, etc.?

Re: [Solved] Insert formula with quotation marks into cell

Posted: Fri Dec 01, 2023 7:42 pm
by JeJe
The API is here

https://www.openoffice.org/api/docs/com ... le-ix.html

https://www.openoffice.org/api/docs/com ... le-ix.html

Take a look at Pitonyak's OpenOffice Macro Information guides

https://www.pitonyak.org/oo.php

If you use MRI you can see what properties and methods are available for any object

viewtopic.php?t=49294